Skip to content

Commit 5fa0a3b

Browse files
chrisruegerCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
1 parent 26dee45 commit 5fa0a3b

11 files changed

Lines changed: 22 additions & 35 deletions

File tree

biz.aQute.bndlib.tests/test/test/ProjectTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,10 @@ private void stale(Project project, boolean b) throws Exception {
551551
}
552552

553553
/**
554-
* Verify that JarArtifactLifecycleListener plugins are called at the right
555-
* times.
554+
* Verify that JarLifecycleListener plugins are called at the right times.
556555
*/
557556
@Test
558-
public void testJarArtifactLifecycleListenerIntegration() throws Exception {
559-
Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
557+
public void testJarLifecycleListenerIntegration() throws Exception {
560558
Project project = ws.getProject("p-stale");
561559
assertNotNull(project);
562560

@@ -589,14 +587,13 @@ public void afterWrite(Project p, File outputFile, Jar jar, Map<String, Object>
589587
}
590588

591589
/**
592-
* Verify that WriteContext is passed correctly and allows data exchange.
590+
* Verify that the context map is passed correctly and allows data exchange.
593591
*/
594592
@Test
595593
public void testJarArtifactWriteContextDataExchange() throws Exception {
596594
Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
597595
Project project = ws.getProject("p-stale");
598596

599-
AtomicReference<String> beforeData = new AtomicReference<>();
600597
AtomicReference<String> afterData = new AtomicReference<>();
601598

602599
JarLifecycleListener testListener = new JarLifecycleListener() {

biz.aQute.bndlib/src/aQute/bnd/build/Project.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ private void beforeJarWrite(Jar jar, File outputFile, Map<String, Object> contex
21502150
try {
21512151
listener.beforeWrite(this, jar, outputFile, context);
21522152
} catch (Exception e) {
2153-
logger.debug("Exception in JarArtifactLifecycleListener.beforeJarWrite", e);
2153+
logger.debug("Exception in JarLifecycleListener.beforeWrite", e);
21542154
}
21552155
}
21562156
}

biz.aQute.bndlib/src/aQute/bnd/service/JarLifecycleListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* public class DigestListener implements JarLifecycleListener {
5454
*
5555
* &#64;Override
56-
* public void beforeJarWrite(Project project, Jar jar, File outputFile, Map&lt;String, Object&gt; context)
56+
* public void beforeWrite(Project project, Jar jar, File outputFile, Map&lt;String, Object&gt; context)
5757
* throws Exception {
5858
* // Compute digest before the JAR is written to disk
5959
* byte[] digest = jar.getTimelessDigest();
@@ -62,7 +62,7 @@
6262
* }
6363
*
6464
* &#64;Override
65-
* public void afterJarWrite(Project project, File outputFile, Jar jar, Map&lt;String, Object&gt; context)
65+
* public void afterWrite(Project project, File outputFile, Jar jar, Map&lt;String, Object&gt; context)
6666
* throws Exception {
6767
* // Retrieve the computed digest
6868
* String digestHex = (String) context.get("digestHex");

bndtools.core/src/bndtools/central/Central.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ public static void applyRebuildTriggerPolicy(Workspace ws) {
367367
BndPreferences prefs = new BndPreferences();
368368
String policy = prefs.getRebuildTriggerPolicy();
369369
ws.getPlugins(JarLifecycleListener.class)
370-
.forEach(p -> ws.removeBasicPlugin(p));
370+
.stream()
371+
.filter(p -> p instanceof RebuildTriggerPolicyPlugin)
372+
.forEach(ws::removeBasicPlugin);
371373
ws.addBasicPlugin(new RebuildTriggerPolicyPlugin(policy));
372374
}
373375

bndtools.core/src/bndtools/central/RebuildTriggerPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* </ul>
3838
* <p>
3939
* The API-based optimization helps prevent rebuild cascades in dependent
40-
* projects when only internal implementation changes occur. *
40+
* projects when only internal implementation changes occur.
4141
* <h2>Timestamp Preservation Strategy</h2>
4242
* <p>
4343
* To avoid unnecessary cascade rebuilds when only non-API changes occur, this

bndtools.core/src/bndtools/explorer/BndtoolsExplorer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,14 @@ public void run() {
498498
rebuildPolicyAction.setText("Rebuild: Optimized");
499499
rebuildPolicyAction.setToolTipText(
500500
"Rebuild Trigger Policy: API-based rebuild optimization enabled - non-API changes just rebuild the current project and won't trigger cascades");
501+
rebuildPolicyAction.setImageDescriptor(null);
501502
} else if (REBUILDTRIGGERPOLICY_ALWAYS.equals(policy)) {
502503
rebuildPolicyAction.setText("Rebuild: Always");
503504
rebuildPolicyAction.setToolTipText("Rebuild Trigger Policy: All changes trigger downstream rebuilds");
505+
rebuildPolicyAction.setImageDescriptor(null);
504506
} else {
505507
rebuildPolicyAction.setText("Rebuild: Unknown");
508+
rebuildPolicyAction.setToolTipText("Rebuild Trigger Policy: Unknown value '" + policy + "'");
506509
rebuildPolicyAction.setImageDescriptor(Icons.desc("errors"));
507510
}
508511
toolBarManager.update(true);

bndtools.core/src/bndtools/preferences/BndPreferences.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ public boolean isParallel() {
339339
/**
340340
* Returns the stored rebuild trigger policy preference.
341341
*
342-
* @return the stored policy string, or an empty string if the Default option is selected (meaning
343-
* the value from {@code build.bnd} should be used without Eclipse overriding it).
344-
*/
342+
* @return the stored policy string; defaults to {@code "always"}.
345343
public String getRebuildTriggerPolicy() {
346344
return store.getString(PREF_REBUILD_TRIGGER_POLICY);
347345
}
@@ -355,10 +353,8 @@ public String getRebuildTriggerPolicy() {
355353
* value is stored as-is but treated as {@code "always"} by the
356354
* build infrastructure.
357355
*/
358-
public void setRebuildTriggerPolicy(String policy) {
359-
store.setValue(PREF_REBUILD_TRIGGER_POLICY,
360-
policy == null ? REBUILDTRIGGERPOLICY_ALWAYS : policy);
361-
}
356+
String normalized = "api".equals(policy) ? policy : REBUILDTRIGGERPOLICY_ALWAYS;
357+
store.setValue(PREF_REBUILD_TRIGGER_POLICY, normalized);
362358

363359
public Closeable onString(String key, Consumer<String> listener) {
364360
IPropertyChangeListener l = e -> {

bndtools.core/src/bndtools/preferences/ui/BndBuildPreferencePage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected Control createContents(Composite parent) {
9191
+ "Limitations: If you have a jar dependency on the path that you are pulling classes into your bundle \n"
9292
+ "e.g. via -includepackage or -conditionalpackage, these need to be rebuilt \n"
9393
+ "even if the public API of the dependency hasn't changed.\n"
94-
+ "This policy not work well in such cases.");
94+
+ "This policy does not work well in such cases.");
9595
lblOptimizedDesc.setForeground(composite.getDisplay()
9696
.getSystemColor(SWT.COLOR_DARK_GRAY));
9797
descData = new GridData(SWT.FILL, SWT.CENTER, true, false);

bndtools.core/test/bndtools/tasks/RebuildTriggerTest.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,12 @@ private static File getDigestFile(File jarFile) {
132132
}
133133

134134
/**
135-
* Check that the JAR timestamp is preserved when the content changes
136-
* Verify that the JAR's timestamp is preserved when the JAR content
137-
* changes but the exported API surface remains identical. The
138-
* optimization works by comparing a stored API-digest sidecar file
139-
* with the newly computed API digest during build. When they match,
140-
* the old file timestamp is kept so that downstream timestamp-based
141-
* staleness checks don't trigger unnecessary cascade rebuilds.
142-
* <p>
143-
* Since the p-stale test project is {@code -resourceonly} (no
144-
* exported packages), this test simulates the mechanism directly:
145-
* we write a known API digest, change the project content so the
146-
* full content digest changes, and verify that timestamp
147-
* preservation still engages via the API digest fallback.
135+
* Verify that timestamp preservation does not engage when the JAR content
136+
* changes and an API digest cannot be computed (e.g. a resource-only bundle
137+
* with no Export-Package).
148138
*/
149139
@Test
150-
public void testApiDigestPreservesTimestampWhenApiUnchanged() throws Exception {
140+
public void testTimestampNotPreservedWhenApiDigestMissing() throws Exception {
151141
Workspace ws = getWorkspace(IO.getFile("testdata/ws"));
152142
ws.addBasicPlugin(new RebuildTriggerPolicyPlugin(RebuildTriggerPolicy.REBUILDTRIGGERPOLICY_API));
153143
Project project = ws.getProject("p-stale");

docs/_plugins/00-overview.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ Your plugin needs to implement an interface which is used in the bnd codebase. F
6666
### Error Handling
6767

6868
Most plugins follow a pattern where exceptions are logged but do not stop the build. Consult the specific plugin documentation for error behavior.
69-
```
7069

7170
## Tagging of repository plugins
7271

0 commit comments

Comments
 (0)