This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new ca8fba541e [FELIX-6493] Extend is-up-to-date logic of Manifest goal
new 668bfc4f0d Merge pull request #124 from HannesWell/manifst_isUpToDate
ca8fba541e is described below
commit ca8fba541e4a40ef7f91fda2036112872c49ad46
Author: Hannes Wellmann <[email protected]>
AuthorDate: Wed Dec 29 18:24:00 2021 +0100
[FELIX-6493] Extend is-up-to-date logic of Manifest goal
- check if the MANIFEST.MF file to generate even exists
- consider modifications of pom.xml (and its parents)
- write incremental-info after manifest to not self-cause out-of-date
---
.../apache/felix/bundleplugin/ManifestPlugin.java | 65 ++++++++++++++++++----
1 file changed, 53 insertions(+), 12 deletions(-)
diff --git
a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
index b15c26b4de..30a7006018 100644
---
a/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
+++
b/tools/maven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
@@ -103,13 +103,17 @@ public class ManifestPlugin extends BundlePlugin
protected void execute( Map<String, String> instructions, ClassPathItem[]
classpath )
throws MojoExecutionException
{
+ File outputFile = new File( manifestLocation, "MANIFEST.MF" );
+ boolean metadataUpToDate = isMetadataUpToDate(outputFile, project);
- if (supportIncrementalBuild && isUpToDate(project)) {
+ if (supportIncrementalBuild && metadataUpToDate &&
isUpToDate(project)) {
return;
}
// 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())) {
+ if (buildContext.isIncremental() && (!supportIncrementalBuild //
+ || (metadataUpToDate &&
!anyJavaSourceFileTouchedSinceLastBuild())))
+ {
getLog().debug("Skipping manifest generation because no java
source file was added, updated or removed since last build.");
return;
}
@@ -118,10 +122,6 @@ public class ManifestPlugin extends BundlePlugin
try
{
analyzer = getAnalyzer(project, instructions, classpath);
-
- if (supportIncrementalBuild) {
- writeIncrementalInfo(project);
- }
}
catch ( FileNotFoundException e )
{
@@ -143,11 +143,13 @@ public class ManifestPlugin extends BundlePlugin
throw new MojoExecutionException( "Internal error in
maven-bundle-plugin", e );
}
- File outputFile = new File( manifestLocation, "MANIFEST.MF" );
-
try
{
writeManifest( analyzer, outputFile, niceManifest, exportScr,
scrLocation, buildContext, getLog() );
+
+ if (supportIncrementalBuild) {
+ writeIncrementalInfo(project);
+ }
}
catch ( Exception e )
{
@@ -364,7 +366,7 @@ public class ManifestPlugin extends BundlePlugin
w.append(curdata);
}
} catch (IOException e) {
- throw new MojoExecutionException("Error checking manifest uptodate
status", e);
+ throw getManifestUptodateCheckException(e);
}
}
@@ -379,7 +381,7 @@ public class ManifestPlugin extends BundlePlugin
}
String curdata = getIncrementalData();
if (curdata.equals(prvdata)) {
- long lastmod = Files.getLastModifiedTime(cacheData).toMillis();
+ long lastmod = lastModified(cacheData);
Set<String> stale = Stream.concat(Stream.of(new
File(project.getBuild().getOutputDirectory())),
project.getArtifacts().stream().map(Artifact::getFile))
.flatMap(f -> newer(lastmod, f))
@@ -404,11 +406,45 @@ public class ManifestPlugin extends BundlePlugin
}
}
} catch (IOException e) {
- throw new MojoExecutionException("Error checking manifest uptodate
status", e);
+ throw getManifestUptodateCheckException(e);
}
return false;
}
+ private boolean isMetadataUpToDate(File outputFile, MavenProject project)
+ throws MojoExecutionException
+ {
+ if (!outputFile.isFile()) // does MANIFEST.MF exist?
+ {
+ getLog().info("No MANIFEST.MF file found, generating manifest.");
+ return false;
+ }
+ try
+ { // is pom.xml up-to-date?
+ Path cacheData = getIncrementalDataPath(project);
+ long manifestLastModified = lastModified(cacheData);
+ while (project != null)
+ {
+ Path pom = project.getFile().toPath();
+ if (manifestLastModified < lastModified(pom))
+ {
+ return false;
+ }
+ project = project.getParent();
+ }
+ }
+ catch (IOException e)
+ {
+ throw getManifestUptodateCheckException(e);
+ }
+ return true;
+ }
+
+ private static MojoExecutionException
getManifestUptodateCheckException(IOException e)
+ {
+ return new MojoExecutionException("Error checking manifest uptodate
status", e);
+ }
+
private String getIncrementalData() {
return getInstructions().entrySet().stream().map(e -> e.getKey() + "="
+ e.getValue())
.collect(Collectors.joining("\n", "", "\n"));
@@ -421,12 +457,17 @@ public class ManifestPlugin extends BundlePlugin
private long lastmod(Path p) {
try {
- return Files.getLastModifiedTime(p).toMillis();
+ return lastModified(p);
} catch (IOException e) {
return 0;
}
}
+ private static long lastModified(Path p) throws IOException
+ {
+ return Files.getLastModifiedTime(p).toMillis();
+ }
+
private Stream<String> newer(long lastmod, File file) {
try {
if (file.isDirectory()) {