You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/05/11 07:25:47 UTC
svn commit: r1743325 - in /felix/trunk/tools/maven-bundle-plugin: pom.xml
src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
Author: cziegeler
Date: Wed May 11 07:25:47 2016
New Revision: 1743325
URL: http://svn.apache.org/viewvc?rev=1743325&view=rev
Log:
FELIX-4009 : maven bundle plugin should be integrated directly with eclipse. Apply second patch from Stefan Seifert
Modified:
felix/trunk/tools/maven-bundle-plugin/pom.xml
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
Modified: felix/trunk/tools/maven-bundle-plugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/pom.xml?rev=1743325&r1=1743324&r2=1743325&view=diff
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/pom.xml (original)
+++ felix/trunk/tools/maven-bundle-plugin/pom.xml Wed May 11 07:25:47 2016
@@ -21,7 +21,7 @@
<parent>
<artifactId>felix-parent</artifactId>
<groupId>org.apache.felix</groupId>
- <version>3</version>
+ <version>4</version>
<relativePath>../pom/pom.xml</relativePath>
</parent>
Modified: felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1743325&r1=1743324&r2=1743325&view=diff
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java Wed May 11 07:25:47 2016
@@ -289,7 +289,7 @@ public class BundlePlugin extends Abstra
* The Maven project.
*/
@Parameter( defaultValue = "${project}", readonly = true, required = true )
- private MavenProject project;
+ protected MavenProject project;
/**
* The BND instructions for the bundle.
@@ -523,7 +523,7 @@ public class BundlePlugin extends Abstra
try
{
- ManifestPlugin.writeManifest( builder, outputFile, niceManifest, exportScr, scrLocation, buildContext );
+ ManifestPlugin.writeManifest( builder, outputFile, niceManifest, exportScr, scrLocation, buildContext, getLog() );
}
catch ( IOException e )
{
Modified: felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java?rev=1743325&r1=1743324&r2=1743325&view=diff
==============================================================================
--- felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java (original)
+++ felix/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java Wed May 11 07:25:47 2016
@@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
@@ -34,6 +35,7 @@ import java.util.jar.Manifest;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -41,6 +43,8 @@ import org.apache.maven.plugins.annotati
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.dependency.graph.DependencyNode;
+import org.codehaus.plexus.util.Scanner;
+import org.osgi.service.metatype.MetaTypeService;
import org.sonatype.plexus.build.incremental.BuildContext;
import aQute.bnd.header.Parameters;
@@ -67,6 +71,14 @@ public class ManifestPlugin extends Bund
@Parameter( property = "rebuildBundle" )
protected boolean rebuildBundle;
+ /**
+ * When true, manifest generation on incremental builds is supported in IDEs like Eclipse.
+ * Please note that the underlying BND library does not support incremental build, which means
+ * always the whole manifest and SCR metadata is generated.
+ */
+ @Parameter( property = "supportIncrementalBuild" )
+ private boolean supportIncrementalBuild;
+
@Component
private BuildContext buildContext;
@@ -74,6 +86,14 @@ public class ManifestPlugin extends Bund
protected void execute( MavenProject project, DependencyNode dependencyGraph, Map<String, String> instructions, Properties properties, Jar[] classpath )
throws MojoExecutionException
{
+
+ // in incremental build execute manifest generation only when explicitly activated
+ // and when any java file was touched since last build
+ if (buildContext.isIncremental() && !(supportIncrementalBuild && anyJavaSourceFileTouchedSinceLastBuild())) {
+ getLog().debug("Skipping manifest generation because no java source file was added, updated or removed since last build.");
+ return;
+ }
+
Analyzer analyzer;
try
{
@@ -103,7 +123,7 @@ public class ManifestPlugin extends Bund
try
{
- writeManifest( analyzer, outputFile, niceManifest, exportScr, scrLocation, buildContext );
+ writeManifest( analyzer, outputFile, niceManifest, exportScr, scrLocation, buildContext, getLog() );
}
catch ( Exception e )
{
@@ -121,7 +141,29 @@ public class ManifestPlugin extends Bund
}
}
}
-
+
+ /**
+ * Checks if any *.java file was added, updated or removed since last build in any source directory.
+ */
+ private boolean anyJavaSourceFileTouchedSinceLastBuild() {
+ @SuppressWarnings("unchecked")
+ List<String> sourceDirectories = project.getCompileSourceRoots();
+ for (String sourceDirectory : sourceDirectories) {
+ File directory = new File(sourceDirectory);
+ Scanner scanner = buildContext.newScanner(directory);
+ Scanner deleteScanner = buildContext.newDeleteScanner(directory);
+ if (containsJavaFile(scanner) || containsJavaFile(deleteScanner)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ private boolean containsJavaFile(Scanner scanner) {
+ String[] includes = new String[] { "**/*.java" };
+ scanner.setIncludes(includes);
+ scanner.scan();
+ return scanner.getIncludedFiles().length > 0;
+ }
public Manifest getManifest( MavenProject project, DependencyNode dependencyGraph, Jar[] classpath ) throws IOException, MojoFailureException,
MojoExecutionException, Exception
@@ -140,7 +182,7 @@ public class ManifestPlugin extends Bund
if (exportScr)
{
- exportScr(analyzer, jar, scrLocation, buildContext);
+ exportScr(analyzer, jar, scrLocation, buildContext, getLog() );
}
// cleanup...
@@ -149,9 +191,11 @@ public class ManifestPlugin extends Bund
return manifest;
}
- private static void exportScr(Analyzer analyzer, Jar jar, File scrLocation, BuildContext buildContext) throws Exception {
+ private static void exportScr(Analyzer analyzer, Jar jar, File scrLocation, BuildContext buildContext, Log log ) throws Exception {
+ log.debug("Export SCR metadata to: " + scrLocation.getPath());
scrLocation.mkdirs();
+ // export SCR metadata files from OSGI-INF/
String bpHeader = analyzer.getProperty(Analyzer.SERVICE_COMPONENT);
Parameters map = Processor.parseHeader(bpHeader, null);
for (String root : map.keySet())
@@ -163,7 +207,7 @@ public class ManifestPlugin extends Bund
Resource resource = jar.getResource(root);
if (resource != null)
{
- writeSCR(resource, location, buildContext);
+ writeSCR(resource, location, buildContext, log);
}
}
else
@@ -172,14 +216,27 @@ public class ManifestPlugin extends Bund
{
String path = entry.getKey();
Resource resource = entry.getValue();
- writeSCR(resource, new File(location, path), buildContext);
+ writeSCR(resource, new File(location, path), buildContext, log);
}
}
}
+
+ // export metatype files from OSGI-INF/metatype
+ Map<String,Resource> metatypeDir = jar.getDirectories().get(MetaTypeService.METATYPE_DOCUMENTS_LOCATION);
+ if (metatypeDir != null) {
+ for (Map.Entry<String, Resource> entry : metatypeDir.entrySet())
+ {
+ String path = entry.getKey();
+ Resource resource = entry.getValue();
+ writeSCR(resource, new File(scrLocation, path), buildContext, log);
+ }
+ }
+
}
- private static void writeSCR(Resource resource, File destination, BuildContext buildContext) throws Exception
+ private static void writeSCR(Resource resource, File destination, BuildContext buildContext, Log log ) throws Exception
{
+ log.debug("Write SCR file: " + destination.getPath());
destination.getParentFile().mkdirs();
OutputStream os = buildContext.newFileOutputStream(destination);
try
@@ -291,7 +348,7 @@ public class ManifestPlugin extends Bund
public static void writeManifest( Analyzer analyzer, File outputFile, boolean niceManifest,
- boolean exportScr, File scrLocation, BuildContext buildContext ) throws Exception
+ boolean exportScr, File scrLocation, BuildContext buildContext, Log log ) throws Exception
{
Properties properties = analyzer.getProperties();
Jar jar = analyzer.getJar();
@@ -317,18 +374,19 @@ public class ManifestPlugin extends Bund
File parentFile = outputFile.getParentFile();
parentFile.mkdirs();
}
- writeManifest( manifest, outputFile, niceManifest, buildContext );
+ writeManifest( manifest, outputFile, niceManifest, buildContext, log );
if (exportScr)
{
- exportScr(analyzer, jar, scrLocation, buildContext);
+ exportScr(analyzer, jar, scrLocation, buildContext, log);
}
}
public static void writeManifest( Manifest manifest, File outputFile, boolean niceManifest,
- BuildContext buildContext ) throws IOException
+ BuildContext buildContext, Log log ) throws IOException
{
+ log.debug("Write manifest to " + outputFile.getPath());
outputFile.getParentFile().mkdirs();
OutputStream os = buildContext.newFileOutputStream( outputFile );