Skip to content

Commit 1344bbf

Browse files
committed
Use cache when writing the manifest and jar
Signed-off-by: Guillaume Nodet <[email protected]>
1 parent a644f2d commit 1344bbf

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

maven-plugins/bnd-maven-plugin/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<groupId>org.slf4j</groupId>
4848
<artifactId>slf4j-api</artifactId>
4949
</dependency>
50+
<dependency>
51+
<groupId>org.codehaus.plexus</groupId>
52+
<artifactId>plexus-utils</artifactId>
53+
</dependency>
5054

5155

5256
<!-- dependencies to annotations -->

maven-plugins/bnd-maven-plugin/src/main/java/aQute/bnd/maven/plugin/AbstractBndMavenPlugin.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.apache.maven.project.MavenProjectHelper;
6767
import org.apache.maven.settings.Settings;
6868
import org.apache.maven.shared.mapping.MappingUtils;
69+
import org.codehaus.plexus.util.io.CachingOutputStream;
6970
import org.slf4j.Logger;
7071
import org.slf4j.LoggerFactory;
7172
import org.sonatype.plexus.build.incremental.BuildContext;
@@ -457,8 +458,12 @@ private void attachArtifactToProject(Jar bndJar) throws Exception {
457458

458459
Files.createDirectories(artifactFile.toPath()
459460
.getParent());
460-
try (OutputStream os = buildContext.newFileOutputStream(artifactFile)) {
461+
try (CachingOutputStream os = new CachingOutputStream(artifactFile)) {
461462
bndJar.write(os);
463+
os.flush();
464+
if (os.isModified()) {
465+
buildContext.refresh(artifactFile);
466+
}
462467
}
463468
buildContext.setValue(LAST_MODIFIED, artifactFile.lastModified());
464469
}
@@ -613,8 +618,12 @@ private void writeContent(Jar jar, File directory) throws Exception {
613618
}
614619
Files.createDirectories(outFile.toPath()
615620
.getParent());
616-
try (OutputStream out = buildContext.newFileOutputStream(outFile)) {
621+
try (CachingOutputStream out = new CachingOutputStream(outFile)) {
617622
IO.copy(resource.openInputStream(), out);
623+
out.flush();
624+
if (out.isModified()) {
625+
buildContext.refresh(outFile);
626+
}
618627
}
619628
}
620629
}
@@ -632,8 +641,12 @@ private void writeManifest(Jar jar, File manifestPath) throws Exception {
632641
}
633642
Files.createDirectories(manifestPath.toPath()
634643
.getParent());
635-
try (OutputStream manifestOut = buildContext.newFileOutputStream(manifestPath)) {
644+
try (CachingOutputStream manifestOut = new CachingOutputStream(manifestPath)) {
636645
jar.writeManifest(manifestOut);
646+
manifestOut.flush();
647+
if (manifestOut.isModified()) {
648+
buildContext.refresh(manifestPath);
649+
}
637650
}
638651
buildContext.setValue(LAST_MODIFIED, manifestPath.lastModified());
639652
}

maven-plugins/bnd-plugin-parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@
196196
<version>${osgi.annotation.version}</version>
197197
<scope>provided</scope>
198198
</dependency>
199+
<dependency>
200+
<groupId>org.codehaus.plexus</groupId>
201+
<artifactId>plexus-utils</artifactId>
202+
<version>3.6.0</version>
203+
</dependency>
199204
</dependencies>
200205
</dependencyManagement>
201206

0 commit comments

Comments
 (0)