Skip to content

Commit

Permalink
[MDEP-674] Add IDE build support (#257)
Browse files Browse the repository at this point in the history
Use BuildContext to notify about newly generated files/folders
  • Loading branch information
kwin committed Nov 22, 2022
1 parent 0eabeef commit 50a4b70
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pom.xml
Expand Up @@ -247,6 +247,15 @@ under the License.
<version>${resolverVersion}</version>
<scope>provided</scope>
</dependency>
<!-- IDE build support (https://github.com/codehaus-plexus/plexus-build-api) -->
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>0.0.7</version><!-- stick with old GAV until https://github.com/eclipse-m2e/m2e-core/issues/944 is fixed -->
<scope>compile</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
Expand All @@ -265,8 +274,6 @@ under the License.
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.StringUtils;
import org.sonatype.plexus.build.incremental.BuildContext;

/**
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
Expand All @@ -59,6 +60,22 @@ public abstract class AbstractDependencyMojo
@Component
private ArchiverManager archiverManager;


/**
* For IDE build support
*/
@Component
private BuildContext buildContext;

/**
* Skip plugin execution only during incremental builds (e.g. triggered from M2E).
*
* @since 3.4.0
* @see #skip
*/
@Parameter( defaultValue = "false" )
private boolean skipDuringIncrementalBuild;

/**
* <p>
* will use the jvm chmod, this is available for user and all level group level will be ignored
Expand Down Expand Up @@ -189,6 +206,7 @@ protected void copyFile( File artifact, File destFile )
}

FileUtils.copyFile( artifact, destFile );
buildContext.refresh( destFile );
}
catch ( IOException e )
{
Expand Down Expand Up @@ -326,6 +344,7 @@ protected void unpack( Artifact artifact, String type, File location, String inc
{
throw new MojoExecutionException( "Error unpacking file: " + file + " to: " + location, e );
}
buildContext.refresh( location );
}

private void silenceUnarchiver( UnArchiver unArchiver )
Expand Down Expand Up @@ -410,6 +429,10 @@ public void setUseJvmChmod( boolean useJvmChmod )
*/
public boolean isSkip()
{
if ( skipDuringIncrementalBuild && buildContext.isIncremental() )
{
return true;
}
return skip;
}

Expand Down

0 comments on commit 50a4b70

Please sign in to comment.