You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Arnaud Bailly <ab...@oqube.com> on 2007/01/29 09:06:06 UTC
maven embedder pb
Hello to all,
I am using MavenEmbedder to do some integration testing for a maven
plugin I wrote. It works quite fine but it seems that configuration
inside execution are ignored. Any clue about that ?
Here is the code snippet:
package oqube.muse;
import java.io.File;
import java.util.Collections;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import oqube.muse.literate.LiterateMuse;
import org.apache.maven.BuildFailureException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.cli.ConsoleDownloadMonitor;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.PlexusLoggerAdapter;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.util.dag.CycleDetectedException;
/**
* Integration testing class for literate muse plugin. This class run plugin
* with projects using maven embedder and chekcs generation is ok.
*
* @author nono
*
*/
public class MavenPluginTest extends TestCase {
private MavenEmbedder maven;
protected void setUp() throws Exception {
super.setUp();
maven = new MavenEmbedder();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
maven.setClassLoader(classLoader);
maven.setLogger(new MavenEmbedderConsoleLogger());
maven.start();
}
public void test01() throws CycleDetectedException, LifecycleExecutionException, BuildFailureException, DuplicateProjectException, ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException {
File targetDirectory = new File("target/test-classes/testPlugin01");
File pomFile = new File(targetDirectory, "pom.xml");
MavenProject pom = maven.readProjectWithDependencies(pomFile);
EventMonitor eventMonitor = new DefaultEventMonitor(
new PlexusLoggerAdapter(new MavenEmbedderConsoleLogger()));
maven.execute(pom, Collections.singletonList("muse:publish"), eventMonitor,
new ConsoleDownloadMonitor(), null, targetDirectory);
// check generated data
File gen = new File(targetDirectory,"target/generated-sources/literate/toto/Toto.java");
assertTrue(gen.exists() && gen.length() > 0);
}
}
and here is the test pom
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>oqube</groupId>
<artifactId>oqube-site-fr</artifactId>
<packaging>jar</packaging>
<version>1.1</version>
<name>OQube Site Francais</name>
<url>http://www.oqube.com/</url>
<inceptionYear>2006</inceptionYear>
<organization>
<name>OQube</name>
<url>http://www.oqube.com/contact.html</url>
</organization>
<build>
<plugins>
<!-- build french and english site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<locales>fr,en</locales>
</configuration>
</plugin>
<plugin>
<groupId>oqube.muse</groupId>
<artifactId>muse-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>tests</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<sourceOutput>target/generated-test-sources</sourceOutput>
<testSource>true</testSource>
<filterIn>.*Test.java</filterIn>
<lenient>true</lenient>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<site>
<id>oqube.com</id>
<url>scp://www.oqube.com/var/www/</url>
</site>
</distributionManagement>
<repositories>
<repository>
<id>oqube.com</id>
<url>http://www.oqube.com/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.0-alpha-8-muse</version>
</dependency>
</dependencies>
<reporting>
<excludeDefaults>true</excludeDefaults>
</reporting>
</project>
Help appreciated...
--
OQube < software engineering \ génie logiciel >
Arnaud Bailly, Dr.
\web> http://www.oqube.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: maven embedder pb
Posted by Arnaud Bailly <ab...@oqube.com>.
franz see <fr...@gmail.com> writes:
> Good day to you, Arnaud,
>
Thanks fro your answer Franz,
That's actually the way I did it. Here is the mojo code:
/*______________________________________________________________________________
*
* Copyright (C) 2006 Arnaud Bailly / OQube
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* email: contact@oqube.com
* creation: Thu Sep 21 2006
*/
package oqube.muse.maven;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import oqube.muse.literate.LiterateMuse;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.project.MavenProject;
/**
* This plugin generates source files and documentation from literate sources in
* muse format. This plugin executes normally at the beginning of a lifecycle
* (phase <code>generate-sources</code>) and does the following:
* <ul>
* <li>Parse literate muse files found in the <code>source</code> parameter,</li>
* <li>Generate corresponding source files and store them in the
* <code>sourceOutput</code> parameter,</li>
* <li>Generate muse files from literate source and store them in the
* <code>docOutput</code> parameter.</li>
* </ul>
* This plugin is a simple wrapper around
* {@link oqube.muse.literate.LiterateMuse} class.
*
* @author abailly@oqube.com
* @version $Id: LiterateMuseMojo.java 80 2007-01-29 08:52:36Z /CN=nono $
* @goal publish
* @phase generate-sources
*/
public class LiterateMuseMojo extends AbstractMojo {
/**
* The directory containing literate muse source to parse.
*
* @parameter expression="${basedir}/src/site/muse"
* @required
*/
private File source;
/**
* Exclusion patterns. All files (and directories) from source directory that
* matches one of these patterns are excluded.
*
* @parameter
*/
private List excludes;
/**
* Output directory for generated sources.
*
* @parameter expression="${project.build.directory}/generated-sources/literate"
*/
private File sourceOutput;
/**
* Output directory for generated documentation. This parameter defaults to
* null as the input file themselves may be used for documentation generation.
* If documentation format is different then this paramater shoudl be set
* accordingly.
*
* @parameter
*/
private File docOutput = null;
/**
* The generated documentation format to use. If this is null (the default),
* then no documentation is generated.
*
* @parameter
*/
private String format;
/**
* Name of header file to prepend to each generated source file.
*
* @parameter
*/
private String header;
/**
* Name of footer file to append to each generated source file.
*
* @parameter
*/
private String footer;
/**
* If true, then source files are aggregated over the whole set of input
* files. This allows splitting a source file over several documents and
* producing a single source.
*
* @parameter expression="false"
*/
private boolean multifile;
/**
* The current project object.
*
* @parameter expression="${project}"
* @required
*/
private MavenProject project;
/**
* The encoding used for generating source and document files.
*
* @parameter
*/
private String outputEncoding;
/**
* The encoding used for reading literate sources.
*
* @parameter
*/
private String inputEncoding;
/**
* The inclusion filter for fragments to generate. This pattern can be used to
* control which fragments get their source files generated by the mojo: A
* fragment is generated if it is <em>included</em> and it is not
* <em>excluded</em>.
*
* @parameter expression=".*"
*/
private String filterIn;
/**
* The exclusion filter for fragments to generate. This pattern can be used to
* control which fragments get their source files generated by the mojo. This
* is very useful for distinguishing test and source files.
*
* @parameter expression="^$"
*/
private String filterOut;
/**
* Tells whether processed sources are test sources or standard sources.
*
* @parameter expression="false"
*/
private boolean testSource;
/**
* A flag for literate publishing that says whether missing referenced
* fragments should be ignored or not.
*
* @parameter expression="false"
*/
private boolean lenient;
public void execute() throws MojoExecutionException, MojoFailureException {
// configuring publishing system
LiterateMuse muse = new LiterateMuse();
muse.setHeader(header);
muse.setFooter(footer);
muse.setMultifile(multifile);
muse.setSourceOutputDirectory(sourceOutput);
muse.setOutputEncoding(outputEncoding);
muse.setDocOutputDirectory(docOutput);
muse.setInputEncoding(inputEncoding);
muse.setFormat(format);
muse.setExcludes(excludes);
muse.setLog(new LogWrapper(getLog()));
muse.setInclude(Pattern.compile(filterIn));
muse.setExclude(Pattern.compile(filterOut));
muse.setLenient(lenient);
List l = new ArrayList();
l.add(source);
muse.setFiles(l);
// run
try {
muse.run();
// add generated sources to project's source path or test source path
if (project != null)
if (!testSource)
project.addCompileSourceRoot(sourceOutput.getAbsolutePath());
else
project.addTestCompileSourceRoot(sourceOutput.getAbsolutePath());
} catch (Exception e) {
getLog().error(e);
}
}
/**
* For testing purpose only.
*
* @param proj
*/
void setProject(MavenProject proj) {
this.project = project;
}
}
--
OQube < software engineering \ génie logiciel >
Arnaud Bailly, Dr.
\web> http://www.oqube.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: maven embedder pb
Posted by franz see <fr...@gmail.com>.
Good day to you, Arnaud,
Your parameters must match your mojo's fields. And those fields must have an
"@parameter" annotation at the very least.
Since you have sourceOutput, testSource, filterIn, and lenient as
parameters, you should have those as fields as well. Something like
/**
* @parameter
*/
private File sourceOutput;
/**
* @parameter
*/
private File testSource;
/**
* @parameter
*/
private String filterIn;
/**
* @parameter
*/
private lenient;
Cheers,
Franz
Arnaud Bailly-3 wrote:
>
> Hello to all,
> I am using MavenEmbedder to do some integration testing for a maven
> plugin I wrote. It works quite fine but it seems that configuration
> inside execution are ignored. Any clue about that ?
>
> Here is the code snippet:
>
> package oqube.muse;
>
> import java.io.File;
> import java.util.Collections;
> import java.util.regex.Pattern;
>
> import junit.framework.TestCase;
>
> import oqube.muse.literate.LiterateMuse;
>
> import org.apache.maven.BuildFailureException;
> import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
> import org.apache.maven.artifact.resolver.ArtifactResolutionException;
> import org.apache.maven.cli.ConsoleDownloadMonitor;
> import org.apache.maven.embedder.MavenEmbedder;
> import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
> import org.apache.maven.embedder.PlexusLoggerAdapter;
> import org.apache.maven.lifecycle.LifecycleExecutionException;
> import org.apache.maven.monitor.event.DefaultEventMonitor;
> import org.apache.maven.monitor.event.EventMonitor;
> import org.apache.maven.project.DuplicateProjectException;
> import org.apache.maven.project.MavenProject;
> import org.apache.maven.project.ProjectBuildingException;
> import org.codehaus.plexus.util.dag.CycleDetectedException;
>
> /**
> * Integration testing class for literate muse plugin. This class run
> plugin
> * with projects using maven embedder and chekcs generation is ok.
> *
> * @author nono
> *
> */
> public class MavenPluginTest extends TestCase {
>
> private MavenEmbedder maven;
>
> protected void setUp() throws Exception {
> super.setUp();
> maven = new MavenEmbedder();
> ClassLoader classLoader =
> Thread.currentThread().getContextClassLoader();
> maven.setClassLoader(classLoader);
> maven.setLogger(new MavenEmbedderConsoleLogger());
> maven.start();
> }
>
> public void test01() throws CycleDetectedException,
> LifecycleExecutionException, BuildFailureException,
> DuplicateProjectException, ArtifactResolutionException,
> ArtifactNotFoundException, ProjectBuildingException {
> File targetDirectory = new File("target/test-classes/testPlugin01");
> File pomFile = new File(targetDirectory, "pom.xml");
> MavenProject pom = maven.readProjectWithDependencies(pomFile);
> EventMonitor eventMonitor = new DefaultEventMonitor(
> new PlexusLoggerAdapter(new MavenEmbedderConsoleLogger()));
> maven.execute(pom, Collections.singletonList("muse:publish"),
> eventMonitor,
> new ConsoleDownloadMonitor(), null, targetDirectory);
> // check generated data
> File gen = new
> File(targetDirectory,"target/generated-sources/literate/toto/Toto.java");
> assertTrue(gen.exists() && gen.length() > 0);
> }
> }
>
> and here is the test pom
>
> <?xml version="1.0" encoding="UTF-8"?>
> <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>
> <groupId>oqube</groupId>
> <artifactId>oqube-site-fr</artifactId>
> <packaging>jar</packaging>
> <version>1.1</version>
> <name>OQube Site Francais</name>
> <url>http://www.oqube.com/</url>
>
> <inceptionYear>2006</inceptionYear>
> <organization>
> <name>OQube</name>
> <url>http://www.oqube.com/contact.html</url>
> </organization>
>
> <build>
> <plugins>
>
> <!-- build french and english site -->
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-site-plugin</artifactId>
> <configuration>
> <locales>fr,en</locales>
> </configuration>
> </plugin>
>
> <plugin>
> <groupId>oqube.muse</groupId>
> <artifactId>muse-maven-plugin</artifactId>
> <version>1.0-SNAPSHOT</version>
> <executions>
> <execution>
> <id>tests</id>
> <goals>
> <goal>publish</goal>
> </goals>
> <configuration>
> <sourceOutput>target/generated-test-sources</sourceOutput>
> <testSource>true</testSource>
> <filterIn>.*Test.java</filterIn>
> <lenient>true</lenient>
> </configuration>
> </execution>
> </executions>
> </plugin>
> </plugins>
> </build>
>
> <distributionManagement>
> <site>
> <id>oqube.com</id>
> <url>scp://www.oqube.com/var/www/</url>
> </site>
> </distributionManagement>
> <repositories>
> <repository>
> <id>oqube.com</id>
> <url>http://www.oqube.com/maven2/</url>
> </repository>
>
> </repositories>
>
> <dependencies>
> <dependency>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-site-plugin</artifactId>
> <version>2.0-beta-5</version>
> </dependency>
>
> <dependency>
> <groupId>org.apache.maven.doxia</groupId>
> <artifactId>doxia-site-renderer</artifactId>
> <version>1.0-alpha-8-muse</version>
> </dependency>
>
> </dependencies>
>
> <reporting>
> <excludeDefaults>true</excludeDefaults>
> </reporting>
>
> </project>
>
> Help appreciated...
> --
> OQube < software engineering \ génie logiciel >
> Arnaud Bailly, Dr.
> \web> http://www.oqube.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/maven-embedder-pb-tf3134570s177.html#a8701774
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org