FELIX-3643 : Use BuildContext for scanning changed files
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1379421 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/maven-scr-plugin/pom.xml b/scrplugin/maven-scr-plugin/pom.xml
index 285aa04..f0cbaca 100644
--- a/scrplugin/maven-scr-plugin/pom.xml
+++ b/scrplugin/maven-scr-plugin/pom.xml
@@ -66,6 +66,11 @@
<version>1.7.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
+<dependency>
+ <groupId>org.sonatype.plexus</groupId>
+ <artifactId>plexus-build-api</artifactId>
+ <version>0.0.7</version>
+</dependency>
</dependencies>
<build>
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
index f58a21f..6813382 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java
@@ -29,7 +29,8 @@
import org.apache.felix.scrplugin.Source;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.Scanner;
+import org.sonatype.plexus.build.incremental.BuildContext;
public class MavenProjectScanner {
@@ -42,7 +43,10 @@
private final Log log;
- public MavenProjectScanner( final MavenProject project,
+ private final BuildContext buildContext;
+
+ public MavenProjectScanner( final BuildContext buildContext,
+ final MavenProject project,
final String includeString,
final String excludeString,
final Log log) {
@@ -50,6 +54,7 @@
this.includeString = includeString;
this.excludeString = excludeString;
this.log = log;
+ this.buildContext = buildContext;
}
/**
@@ -82,8 +87,7 @@
continue;
}
log.debug( "Scanning source tree " + tree );
- final DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( directory );
+ final Scanner scanner = this.buildContext.newScanner(directory, false);
if ( excludes != null && excludes.length > 0 ) {
scanner.setExcludes( excludes );
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
index 21fe5b4..ff6af89 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
@@ -47,6 +47,7 @@
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;
/**
* The <code>SCRDescriptorMojo</code> generates a service descriptor file based
@@ -174,6 +175,11 @@
private List<String> supportedProjectTypes = Arrays.asList( new String[]
{ "jar", "bundle" } );
+ /**
+ * @component
+ */
+ private BuildContext buildContext;
+
public void execute() throws MojoExecutionException, MojoFailureException {
final String projectType = project.getArtifact().getType();
@@ -189,6 +195,7 @@
// create project
final MavenProjectScanner scanner = new MavenProjectScanner(
+ this.buildContext,
this.project, this.sourceIncludes, this.sourceExcludes, scrLog);
final Project project = new Project();
@@ -227,6 +234,8 @@
this.setServiceComponentHeader(result.getScrFiles());
this.updateProjectResources();
+ // refreshing the target files does not seem to be the right thing
+ //this.updateBuildContext(result);
} catch (final SCRDescriptorException sde) {
throw new MojoExecutionException(sde.getSourceLocation() + " : " + sde.getMessage(), sde);
} catch (final SCRDescriptorFailureException sdfe) {
@@ -235,6 +244,19 @@
}
}
+ private void updateBuildContext(final Result result) {
+ if ( result.getMetatypeFiles() != null ) {
+ for(final String name : result.getMetatypeFiles() ) {
+ this.buildContext.refresh(new File(this.outputDirectory, name.replace('/', File.separatorChar)));
+ }
+ }
+ if ( result.getScrFiles() != null ) {
+ for(final String name : result.getScrFiles() ) {
+ this.buildContext.refresh(new File(this.outputDirectory, name.replace('/', File.separatorChar)));
+ }
+ }
+ }
+
private URL[] getClassPath() throws MojoFailureException {
@SuppressWarnings("unchecked")
final List<Artifact> artifacts = this.project.getCompileArtifacts();
diff --git a/scrplugin/maven-scr-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/scrplugin/maven-scr-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
index 73a7fd5..c497c0f 100644
--- a/scrplugin/maven-scr-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
+++ b/scrplugin/maven-scr-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
@@ -25,7 +25,7 @@
</goals>
</pluginExecutionFilter>
<action>
- <ignore/>
+ <execute/>
</action>
</pluginExecution>
</pluginExecutions>