o lining up all the uses of modello and using 1.0-alpha-13 of the modello plugin everywhere

o add the generation of a JDOMWriter for use in the embedder so that working with models doesn't                                    
  completely whack the existing XML, and allow for outputting the namespace declarations                                            
o add a security manager to the embedder which is off by default but will barf if someone                                           
  tries to set system properties. you have to specifically turn this on because it will more then                                   
  likely break tons of code like xerces setting a system property named "version", nice.       



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@493811 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-01-07 19:13:33 +00:00
parent 056e6ec542
commit 72e7a4df53
11 changed files with 147 additions and 82 deletions

View File

@ -8,4 +8,4 @@ wagon.version=1.0-beta-2
doxia.version=1.0-alpha-9-SNAPSHOT
modello.version=1.0-alpha-13
junit.version=3.8.1
jdom.version=1.0

View File

@ -116,7 +116,9 @@
<pull orgpath="org/codehaus/modello/modello-core" version="${modello.version}" name="modello-core" repository="codehaus"/>
<pull orgpath="org/codehaus/modello/modello-plugin-xml" version="${modello.version}" name="modello-plugin-xml" repository="codehaus"/>
<pull orgpath="org/codehaus/modello/modello-plugin-xpp3" version="${modello.version}" name="modello-plugin-xpp3" repository="codehaus"/>
<pull orgpath="org/codehaus/modello/modello-plugin-jdom" version="${modello.version}" name="modello-plugin-jdom" repository="codehaus"/>
<pull orgpath="junit/junit" version="${junit.version}" name="junit"/>
<pull orgpath="jdom/jdom" version="${jdom.version}" name="jdom"/>
</target>
<target name="classpath-pre" depends="init,pull"
@ -128,7 +130,6 @@
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-component-api/${plexus.version}/plexus-component-api-${plexus.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-classworlds/${classworlds.version}/plexus-classworlds-${classworlds.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-interactivity-api/${plexus-interactivity-api.version}/plexus-interactivity-api-${plexus-interactivity-api.version}.jar"/>
<pathelement location="${maven.repo.local}/org/apache/maven/wagon/wagon-file/${wagon.version}/wagon-file-${wagon.version}.jar"/>
<pathelement location="${maven.repo.local}/org/apache/maven/wagon/wagon-provider-api/${wagon.version}/wagon-provider-api-${wagon.version}.jar"/>
<pathelement location="${maven.repo.local}/org/apache/maven/wagon/wagon-http-lightweight/${wagon.version}/wagon-http-lightweight-${wagon.version}.jar"/>
@ -137,6 +138,7 @@
<pathelement location="${maven.repo.local}/org/apache/maven/wagon/wagon-ssh/${wagon.version}/wagon-ssh-${wagon.version}.jar"/>
<pathelement location="${maven.repo.local}/org/apache/maven/doxia/doxia-sink-api/${doxia.version}/doxia-sink-api-${doxia.version}.jar"/>
<pathelement location="${maven.repo.local}/junit/junit/${junit.version}/junit-${junit.version}.jar"/>
<pathelement location="${maven.repo.local}/jdom/jdom/${jdom.version}/jdom-${jdom.version}.jar"/>
</path>
<!-- DGF Need to keep these modello classes out of the system classpath at runtime, because different parts of the build
need different versions of modello. -->
@ -145,6 +147,7 @@
<pathelement location="${maven.repo.local}/org/codehaus/modello/modello-core/${modello.version}/modello-core-${modello.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/modello/modello-plugin-xml/${modello.version}/modello-plugin-xml-${modello.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/modello/modello-plugin-xpp3/${modello.version}/modello-plugin-xpp3-${modello.version}.jar"/>
<pathelement location="${maven.repo.local}/org/codehaus/modello/modello-plugin-jdom/${modello.version}/modello-plugin-jdom-${modello.version}.jar"/>
<!--
<pathelement location="modello.jar"/>
-->
@ -184,6 +187,7 @@
<modello-single-mode file="@{file}" version="@{version}" mode="java"/>
<modello-single-mode file="@{file}" version="@{version}" mode="xpp3-reader"/>
<modello-single-mode file="@{file}" version="@{version}" mode="xpp3-writer"/>
<modello-single-mode file="@{file}" version="@{version}" mode="jdom-writer"/>
</sequential>
</macrodef>
@ -281,22 +285,6 @@
</chmod>
</target>
<!--
<target name="mits"
description="Run the Maven integration tests."
depends="init">
<java fork="true"
dir="maven-core-integration-tests"
classname="org.apache.maven.cli.MavenCli"
failonerror="true">
<classpath refid="maven.classpath"/>
<arg value="-e"/>
<arg value="clean"/>
<arg value="test"/>
</java>
</target>
-->
<target name="all" depends="clean-bootstrap,init,extract-assembly"/>
<target name="run-full-maven" depends="init,extract-assembly"

View File

@ -79,6 +79,10 @@
<artifactId>maven-tools</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
</dependencies>
<distributionManagement>
<repository>

View File

@ -29,23 +29,21 @@
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.embedder.execution.MavenExecutionRequestDefaultsPopulator;
import org.apache.maven.embedder.writer.WriterUtils;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.model.io.jdom.MavenJDOMWriter;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
@ -61,8 +59,6 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
@ -85,7 +81,7 @@ public class MavenEmbedder
private MavenXpp3Reader modelReader;
private MavenXpp3Writer modelWriter;
private MavenJDOMWriter modelWriter;
private ProfileManager profileManager;
@ -119,6 +115,8 @@ public class MavenEmbedder
private MavenEmbedderLogger logger;
private boolean activateSystemManager;
// ----------------------------------------------------------------------
// User options
// ----------------------------------------------------------------------
@ -143,6 +141,23 @@ public MavenEmbedder( ClassWorld classWorld,
this.logger = logger;
// ----------------------------------------------------------------------------
// Don't override any existing SecurityManager if one has been installed. Our
// SecurityManager just checks to make sure
// ----------------------------------------------------------------------------
try
{
if ( System.getSecurityManager() == null && activateSystemManager )
{
System.setSecurityManager( new MavenEmbedderSecurityManager() );
}
}
catch ( RuntimeException e )
{
logger.warn( "Error trying to set the SecurityManager: " + e.getMessage() );
}
start();
}
@ -189,11 +204,19 @@ public Model readModel( File model )
return modelReader.read( new FileReader( model ) );
}
public void writeModel( Writer writer,
Model model,
boolean namespaceDeclaration )
throws IOException
{
WriterUtils.write( writer, model, true );
}
public void writeModel( Writer writer,
Model model )
throws IOException
{
modelWriter.write( writer, model );
WriterUtils.write( writer, model, false );
}
// ----------------------------------------------------------------------
@ -391,7 +414,8 @@ public void start( MavenEmbedRequest req )
if ( logger != null )
{
MavenEmbedderLoggerManager loggerManager = new MavenEmbedderLoggerManager( new PlexusLoggerAdapter( logger ) );
MavenEmbedderLoggerManager loggerManager =
new MavenEmbedderLoggerManager( new PlexusLoggerAdapter( logger ) );
container.setLoggerManager( loggerManager );
}
@ -410,7 +434,7 @@ public void start( MavenEmbedRequest req )
modelReader = new MavenXpp3Reader();
modelWriter = new MavenXpp3Writer();
modelWriter = new MavenJDOMWriter();
maven = (Maven) container.lookup( Maven.ROLE );

View File

@ -0,0 +1,13 @@
package org.apache.maven.embedder;
/** @author Jason van Zyl */
public class MavenEmbedderSecurityManager
extends SecurityManager
{
public void checkPropertyAccess( String key )
{
super.checkPropertyAccess( key );
throw new SecurityException( "You cannot modify any System properties!" );
}
}

View File

@ -11,6 +11,8 @@
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.Writer;
import java.io.FileWriter;
import java.util.List;
import java.util.Set;
import java.util.Arrays;
@ -40,14 +42,6 @@ protected void tearDown()
maven.stop();
}
public void testMavenEmbedder()
throws Exception
{
modelReadingTest();
projectReadingTest();
}
// ----------------------------------------------------------------------
// Goal/Phase execution tests
// ----------------------------------------------------------------------
@ -170,10 +164,10 @@ public void testLocalRepositoryRetrieval()
}
// ----------------------------------------------------------------------
//
// Model Reading
// ----------------------------------------------------------------------
protected void modelReadingTest()
public void testModelReading()
throws Exception
{
// ----------------------------------------------------------------------
@ -185,7 +179,7 @@ protected void modelReadingTest()
assertEquals( "org.apache.maven", model.getGroupId() );
}
protected void projectReadingTest()
public void testProjectReading()
throws Exception
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPomFile( getPomFile().getAbsolutePath() );
@ -203,6 +197,30 @@ protected void projectReadingTest()
System.out.println( "artifact = " + artifact );
}
// ----------------------------------------------------------------------------
// Model Writing
// ----------------------------------------------------------------------------
public void testModelWriting()
throws Exception
{
Model model = maven.readModel( getPomFile() );
model.setGroupId( "org.apache.maven.new" );
File file = new File( basedir, "target/model.xml" );
Writer writer = new FileWriter( file );
maven.writeModel( writer, model );
writer.close();
model = maven.readModel( file );
assertEquals( "org.apache.maven.new", model.getGroupId() );
}
// ----------------------------------------------------------------------
// Internal Utilities
// ----------------------------------------------------------------------

View File

@ -36,6 +36,14 @@
<version>4.0.0</version>
<model>maven.mdo</model>
</configuration>
<executions>
<execution>
<id>jdom</id>
<goals>
<goal>jdom-writer</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@ -51,8 +59,8 @@
<execution>
<id>v3</id>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-writer</goal>
<goal>xpp3-reader</goal>
<goal>xsd</goal>
</goals>
@ -86,5 +94,9 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -14,24 +14,6 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-7</version>
<executions>
<execution>
<id>site-docs</id>
<phase>pre-site</phase>
<goals>
<goal>xdoc</goal>
<goal>xsd</goal>
</goals>
</execution>
<execution>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-reader</goal>
</goals>
</execution>
</executions>
<configuration>
<version>1.0.0</version>
<model>plugin-registry.mdo</model>

View File

@ -31,28 +31,18 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-7</version>
<executions>
<execution>
<id>site-docs</id>
<phase>pre-site</phase>
<goals>
<goal>xdoc</goal>
<goal>xsd</goal>
</goals>
</execution>
<execution>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-reader</goal>
</goals>
</execution>
</executions>
<configuration>
<version>1.0.0</version>
<model>profiles.mdo</model>
</configuration>
<executions>
<execution>
<id>jdom</id>
<goals>
<goal>jdom-writer</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@ -62,13 +52,18 @@
<artifactId>maven-model</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<!-- Generate model code -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -35,6 +35,14 @@
<version>1.0.0</version>
<model>settings.mdo</model>
</configuration>
<executions>
<execution>
<id>jdom</id>
<goals>
<goal>jdom-writer</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@ -44,13 +52,18 @@
<artifactId>maven-model</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<!-- Generated model code -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
</dependencies>
</project>

18
pom.xml
View File

@ -86,10 +86,20 @@
<tagBase>https://svn.apache.org/repos/asf/maven/components/tags</tagBase>
</configuration>
</plugin>
<!--
./maven-model/maven.mdo
./maven-plugin-descriptor/src/main/mdo/lifecycle.mdo
./maven-plugin-parameter-documenter/src/main/mdo/paramdoc.mdo
./maven-plugin-registry/plugin-registry.mdo
./maven-profile/profiles.mdo
./maven-repository-metadata/src/main/mdo/metadata.mdo
./maven-repository-metadata/src/main/mdo/plugins.mdo
./maven-settings/settings.mdo
-->
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-8</version>
<version>1.0-alpha-13</version>
<executions>
<execution>
<id>site-docs</id>
@ -100,6 +110,7 @@
</goals>
</execution>
<execution>
<id>standard</id>
<goals>
<goal>java</goal>
<goal>xpp3-reader</goal>
@ -210,6 +221,11 @@
<version>1.2_Java1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>