InitializeMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File appDirectory = new File( this.project.getBasedir(), MavenPluginConstants.SOURCE_MODEL_DIRECTORY ); if( appDirectory.exists()) { getLog().debug( "Adding " + MavenPluginConstants.SOURCE_MODEL_DIRECTORY + " to the list of filtered resources." ); Resource res = new Resource(); res.setDirectory( appDirectory.getAbsolutePath()); res.setFiltering( true ); res.getIncludes().add( "***.instances" ); res.getIncludes().add( "***.graph" ); res.getExcludes().add( "***.properties" ); this.project.addResource( res ); } if( Utils.isEmptyOrWhitespaces( this.project.getBuild().getOutputDirectory()) || this.project.getBuild().getOutputDirectory().toLowerCase().endsWith( "/target/classes" )) { getLog().debug( "Changing the default output directory to " + MavenPluginConstants.TARGET_MODEL_DIRECTORY + "." ); File outputDirectory = new File( this.project.getBasedir(), MavenPluginConstants.TARGET_MODEL_DIRECTORY ); this.project.getBuild().setOutputDirectory( outputDirectory.getAbsolutePath()); } }  @Override void execute(); void setProject( MavenProject project );  }
@Test public void checkSourcesDirectoriesAreUpdated() throws Exception { File baseDir = this.resources.getBasedir( "project--valid" ); Assert.assertNotNull( baseDir ); Assert.assertTrue( baseDir.exists()); Assert.assertTrue( baseDir.isDirectory()); File pom = new File( baseDir, "pom.xml" ); InitializeMojo mojo = (InitializeMojo) this.rule.lookupMojo( "initialize", pom ); Assert.assertNotNull( mojo ); final MavenProject mvnProject = new MavenProject() ; mvnProject.setFile( pom ) ; this.rule.setVariableValueToObject( mojo, "project", mvnProject ); Assert.assertNotNull( this.rule.getVariableValueFromObject( mojo, "project" )); List<Resource> list = mvnProject.getResources(); Assert.assertEquals( 0, list.size()); Assert.assertTrue( Utils.isEmptyOrWhitespaces( mvnProject.getBuild().getOutputDirectory())); mojo.execute(); list = mvnProject.getResources(); Assert.assertEquals( 2, list.size()); Resource res = list.get( 0 ); Assert.assertTrue( res.isFiltering()); Assert.assertEquals( new File( baseDir, MavenPluginConstants.SOURCE_MODEL_DIRECTORY ).getAbsolutePath(), res.getDirectory()); res = list.get( 1 ); Assert.assertFalse( res.isFiltering()); Assert.assertEquals( new File( baseDir, MavenPluginConstants.SOURCE_MODEL_DIRECTORY ).getAbsolutePath(), res.getDirectory()); File expectedFile = new File( mvnProject.getBasedir(), MavenPluginConstants.TARGET_MODEL_DIRECTORY ); Assert.assertEquals( expectedFile.getAbsolutePath(), mvnProject.getBuild().getOutputDirectory()); }