Repository: camel Updated Branches: refs/heads/master d5574fdb7 -> b3c02c4cc
First cut of mvn goal to generate/update component readme.md file Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/07bdbad1 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/07bdbad1 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/07bdbad1 Branch: refs/heads/master Commit: 07bdbad13c1e36fdfe91a9214be046df3c52d38c Parents: d5574fd Author: Claus Ibsen <[email protected]> Authored: Tue Dec 29 12:08:50 2015 +0100 Committer: Claus Ibsen <[email protected]> Committed: Tue Jan 26 19:45:09 2016 +0100 ---------------------------------------------------------------------- components/camel-ahc/pom.xml | 19 ++++ .../maven/packaging/ReadmeComponentMojo.java | 97 ++++++++++++++++++++ 2 files changed, 116 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/07bdbad1/components/camel-ahc/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-ahc/pom.xml b/components/camel-ahc/pom.xml index 59fd2f1..610d727 100644 --- a/components/camel-ahc/pom.xml +++ b/components/camel-ahc/pom.xml @@ -85,4 +85,23 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>readme</id> + <goals> + <goal>update-readme</goal> + </goals> + <phase>package</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </project> http://git-wip-us.apache.org/repos/asf/camel/blob/07bdbad1/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java new file mode 100644 index 0000000..8ecfe7d --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java @@ -0,0 +1,97 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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. + */ +package org.apache.camel.maven.packaging; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; +import org.sonatype.plexus.build.incremental.BuildContext; + +/** + * Generate or updates the component readme.md file in the project root directort. + * + * @goal update-readme + */ +public class ReadmeComponentMojo extends AbstractMojo { + + /** + * The maven project. + * + * @parameter property="project" + * @required + * @readonly + */ + protected MavenProject project; + + /** + * The output directory for generated readme file + * + * @parameter default-value="${project.build.directory}" + */ + protected File buildDir; + + /** + * build context to check changed files and mark them for refresh (used for + * m2e compatibility) + * + * @component + * @readonly + */ + private BuildContext buildContext; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + File readmeDir = new File(buildDir, ".."); + File readmeFile = new File(readmeDir, "readme.md"); + + // see if a file with name readme.md exists in any kind of case + String[] names = readmeDir.list(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return "readme.md".equalsIgnoreCase(name); + } + }); + if (names != null && names.length == 1) { + readmeFile = new File(readmeDir, names[0]); + } + + boolean exists = readmeFile.exists(); + if (exists) { + getLog().info("Using existing " + readmeFile.getName() + " file"); + } else { + getLog().info("Creating new readme.md file"); + } + + try { + OutputStream os = buildContext.newFileOutputStream(readmeFile); + os.write("Hello World".getBytes()); + os.close(); + + } catch (IOException e) { + throw new MojoExecutionException("Failed to write to " + readmeFile + ". Reason: " + e, e); + } + + } + + +}
