Permalink
Browse files

Added ability to execute a specified test and then package the docs.

  • Loading branch information...
nawroth committed Nov 27, 2011
1 parent e91ea28 commit 18f2cf418bf6bee1ff8067a0c60a1e7dffd9e07d
View
19 pom.xml
@@ -41,18 +41,35 @@
<artifactId>docs-maven-plugin</artifactId>
<groupId>org.neo4j.build.plugins</groupId>
<version>0.1-SNAPSHOT</version>
- <!--
+ <!-- the directories below will be added by default,
+ using the config element will _replace_ the defaults. -->
+ <!--
<configuration>
<sourceDirectories>
<sourceDirectory>${basedir}/src/docs</sourceDirectory>
<sourceDirectory>${project.build.directory}/docs</sourceDirectory>
</sourceDirectories>
</configuration>
-->
+ <!--
+ <configuration>
+ <executions>
+ <execution>
+ <id>assemble-docs</id>
+ <phase>package</phase>
+ <goals><goal>assemble</goal></goals>
+ </execution>
+ </executions>
+ </configuration>
+ -->
</plugin>
</plugins>
</pluginManagement>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
<plugin>
<artifactId>docs-maven-plugin</artifactId>
<groupId>org.neo4j.build.plugins</groupId>
View
@@ -18,9 +18,9 @@ After installing it, add it to the project:
-->
</plugin>
-Probably execution from the pom.xml works, haven't tried yet.
+Configuring execution from the pom.xml doesn't work yet.
-Now there's two new commands you can use:
+There's two new commands you can use:
mvn docs:assembly
- creates the docs.jar
@@ -30,5 +30,8 @@ mvn docs:assembly
mvn docs:install
- creates and then installs the docs.jar
- mvn3 only
+- CLI only
-
+mvn docs:install -Dtest=DocsTest
+- executes test, then assembles and installs docs.
+- needs more work, but the basic functionality is there
@@ -45,6 +45,8 @@
* uses the install plugin to install the file).
*
* @goal install
+ * @requiresDirectInvocation
+ * @requiresDependencyResolution test
*/
public class InstallMojo extends AbstractMojo
{
@@ -55,6 +57,13 @@
*/
private List<String> sourceDirectories;
+ /**
+ * Test to execute.
+ *
+ * @parameter expression="${test}"
+ */
+ private String test;
+
/**
* The maven project.
*
@@ -87,6 +96,26 @@
@Override
public void execute() throws MojoExecutionException
+ {
+ System.out.println( test );
+ if ( test != null )
+ {
+ executeTest();
+ }
+ assembleInstall();
+ }
+
+ private void executeTest() throws MojoExecutionException
+ {
+ executeMojo(
+ plugin( groupId( "org.apache.maven.plugins" ),
+ artifactId( "maven-surefire-plugin" ), version( "2.10" ) ),
+ goal( "test" ),
+ configuration( element( name( "test" ), test ) ),
+ executionEnvironment( project, session, pluginManager ) );
+ }
+
+ private void assembleInstall() throws MojoExecutionException
{
final File destFile = DocsAssembler.assemble( project, getLog(),
projectHelper, sourceDirectories );
@@ -0,0 +1,49 @@
+package org.neo4j.build.plugins.docs;
+/**
+ * Copyright (c) 2002-2011 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Neo4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.junit.Test;
+
+
+public class DocsTest
+{
+ @Test
+ public void test() throws IOException
+ {
+ File file = new File( "target/docs/subdir1" );
+ file.mkdirs();
+ file = new File( "target/docs/subdir1/otherfile.txt" );
+ Writer out = new OutputStreamWriter( new FileOutputStream( file ),
+ "UTF-8" );
+ try
+ {
+ out.write( "Some file cöntents." );
+ }
+ finally
+ {
+ out.close();
+ }
+ }
+}

0 comments on commit 18f2cf4

Please sign in to comment.