001/* 002 * Copyright (C) 2005 Christian Schulte <cs@schulte.it> 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without 006 * modification, are permitted provided that the following conditions 007 * are met: 008 * 009 * o Redistributions of source code must retain the above copyright 010 * notice, this list of conditions and the following disclaimer. 011 * 012 * o Redistributions in binary form must reproduce the above copyright 013 * notice, this list of conditions and the following disclaimer in 014 * the documentation and/or other materials provided with the 015 * distribution. 016 * 017 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 018 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 019 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 027 * 028 * $JOMC: MainResourcesWriteMojo.java 5228 2016-04-24 11:08:06Z schulte $ 029 * 030 */ 031package org.jomc.mojo; 032 033import java.io.File; 034import org.apache.maven.model.Resource; 035import org.apache.maven.plugin.MojoExecutionException; 036import org.apache.maven.plugins.annotations.LifecyclePhase; 037import org.apache.maven.plugins.annotations.Mojo; 038import org.apache.maven.plugins.annotations.Parameter; 039import org.apache.maven.plugins.annotations.ResolutionScope; 040import org.apache.maven.project.MavenProject; 041 042/** 043 * Writes a projects' main resource files. 044 * 045 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 046 * @version $JOMC: MainResourcesWriteMojo.java 5228 2016-04-24 11:08:06Z schulte $ 047 */ 048@Mojo( name = "write-main-resources", 049 defaultPhase = LifecyclePhase.PROCESS_RESOURCES, 050 requiresDependencyResolution = ResolutionScope.TEST, 051 threadSafe = true ) 052public final class MainResourcesWriteMojo extends AbstractResourcesWriteMojo 053{ 054 055 /** 056 * Execution strategy of the goal ({@code always} or {@code once-per-session}). 057 * 058 * @since 1.1 059 */ 060 @Parameter( name = "writeMainResourcesExecutionStrategy", 061 property = "jomc.writeMainResourcesExecutionStrategy", 062 defaultValue = "once-per-session" ) 063 private String writeMainResourcesExecutionStrategy; 064 065 /** 066 * Directory to write resource files to. 067 * 068 * @since 1.2 069 */ 070 @Parameter( name = "mainResourcesOutputDirectory", 071 property = "jomc.mainResourcesOutputDirectory", 072 defaultValue = "${project.build.directory}/generated-resources/jomc" ) 073 private File mainResourcesOutputDirectory; 074 075 /** 076 * Creates a new {@code MainResourcesWriteMojo} instance. 077 */ 078 public MainResourcesWriteMojo() 079 { 080 super(); 081 } 082 083 @Override 084 protected String getResourcesModuleName() throws MojoExecutionException 085 { 086 return this.getModuleName(); 087 } 088 089 @Override 090 protected ClassLoader getResourcesClassLoader() throws MojoExecutionException 091 { 092 return this.getMainClassLoader(); 093 } 094 095 @Override 096 protected File getResourcesDirectory() throws MojoExecutionException 097 { 098 return this.mainResourcesOutputDirectory; 099 } 100 101 @Override 102 protected String getGoal() throws MojoExecutionException 103 { 104 return "write-main-resources"; 105 } 106 107 @Override 108 protected String getExecutionStrategy() throws MojoExecutionException 109 { 110 return this.writeMainResourcesExecutionStrategy; 111 } 112 113 @Override 114 protected File getResourcesOutputDirectory() throws MojoExecutionException 115 { 116 return this.getOutputDirectory(); 117 } 118 119 @Override 120 protected void addMavenResource( final MavenProject mavenProject, final Resource resource ) 121 throws MojoExecutionException 122 { 123 mavenProject.addResource( resource ); 124 } 125 126}