Skip to content

Commit

Permalink
pull out the logging to MbrCommand only
Browse files Browse the repository at this point in the history
Since MbrUpdater should not print out directly any logging statements, I tried to do it outside in MbrCommand. Because MbrCommand also did the logging before, so I tried do it in a similar way, to preserve existing behavior.

Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
  • Loading branch information
chrisrueger committed May 3, 2024
1 parent c06144f commit 2d1f949
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
19 changes: 18 additions & 1 deletion biz.aQute.bnd/src/aQute/bnd/main/MbrCommand.java
Expand Up @@ -152,11 +152,28 @@ public void _update(UpdateOptions options) throws Exception {
for (MavenBndRepository repo : repos) {
bnd.trace("repo %s", repo.getName());

MbrUpdater mbr = new MbrUpdater(repo, bnd::trace);
MbrUpdater mbr = new MbrUpdater(repo);
Map<Archive, MavenVersion> content = mbr.calculateUpdateRevisions(updates);
content.entrySet()
.forEach(e -> {
Archive archive = e.getKey();
MavenVersion version = e.getValue();

if (version.compareTo(archive.getRevision().version) > 0) {
// log only updates
bnd.trace(" %-70s %20s -> %s%n", archive.getRevision().program, archive.getRevision().version,
version);
}

});

if (!options.dry()) {
if (repo.getIndexFile()
.isFile()) {
bnd.trace("reading %s", repo.getIndexFile());
}
if (mbr.update(content)) {
bnd.trace("writing %s", repo.getIndexFile());
repo.refresh();
}
}
Expand Down
2 changes: 1 addition & 1 deletion biz.aQute.repository/bnd.bnd
Expand Up @@ -56,7 +56,7 @@ Export-Package: \
-builderignore: testresources, testdata

-fixupmessages.tag: "Export aQute.maven.provider,* private references \\[aQute.lib.tag\\]"
-fixupmessages.lib: "Export aQute.bnd.repository.maven.provider,* private references \\[aQute.lib.collections, aQute.lib.getopt, aQute.lib.startlevel\\]"
-fixupmessages.lib: "Export aQute.bnd.repository.maven.provider,* private references \\[aQute.lib.collections, aQute.lib.getopt\\]"
-fixupmessages.configurable: "Export aQute.bnd.repository.osgi,* private references \\[aQute.configurable\\]"

-baseline: *
Expand Down
Expand Up @@ -3,8 +3,8 @@
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
Expand All @@ -16,7 +16,6 @@
import aQute.lib.collections.MultiMap;
import aQute.lib.io.IO;
import aQute.lib.justif.Justif;
import aQute.lib.startlevel.Trace;
import aQute.maven.api.Archive;

/**
Expand All @@ -32,11 +31,9 @@ public class MbrUpdater {
.find();

private final MavenBndRepository repo;
private final Trace logger;

public MbrUpdater(MavenBndRepository repo, Trace logger) {
public MbrUpdater(MavenBndRepository repo) {
this.repo = repo;
this.logger = logger != null ? logger : (format, args) -> {};
}

public enum Scope {
Expand Down Expand Up @@ -78,21 +75,17 @@ public static MultiMap<Archive, MavenVersion> getUpdates(Scope scope, Collection
* Calculates the new revisions for each archive.
*
* @param updates
* @param out optional logger
* @return a map the revision for each archive.
*/
public Map<Archive, MavenVersion> calculateUpdateRevisions(MultiMap<Archive, MavenVersion> updates) {
Map<Archive, MavenVersion> content = new HashMap<>();
Map<Archive, MavenVersion> content = new LinkedHashMap<>();

for (Archive archive : new TreeSet<>(repo.getArchives())) {
List<MavenVersion> list = updates.get(archive);
if (list == null || list.isEmpty()) {
content.put(archive, archive.revision.version);
} else {
MavenVersion version = list.get(list.size() - 1);

logger.trace(" %-70s %20s -> %s%n", archive.getRevision().program, archive.getRevision().version,
version);
content.put(archive, version);
}
}
Expand Down Expand Up @@ -130,7 +123,6 @@ public boolean update(Map<Archive, MavenVersion> map) throws IOException {
repo.getIndexFile()
.getParentFile()
.mkdirs();
logger.trace("writing %s", repo.getIndexFile());
IO.store(sb.toString(), repo.getIndexFile());
return changes;
}
Expand All @@ -152,7 +144,6 @@ private boolean buildGAVString(StringBuilder sb, Map<Archive, MavenVersion> tran
lc = IO.reader(repo.getIndexFile())
.lines()
.iterator();
logger.trace("reading %s", repo.getIndexFile());
} else {
lc = Collections.emptyIterator();
}
Expand Down
Expand Up @@ -33,9 +33,11 @@
class RepoActions {

private MavenBndRepository repo;
private MbrUpdater mbr;

RepoActions(MavenBndRepository mavenBndRepository) {
this.repo = mavenBndRepository;
this.mbr = new MbrUpdater(repo);
}

Map<String, Runnable> getRepoActions(final Clipboard clipboard) throws Exception {
Expand Down Expand Up @@ -250,7 +252,6 @@ private static final void addCopyToClipboardActions(MavenBndRepository repo, fin

private String preview(Scope scope) {
try {
MbrUpdater mbr = new MbrUpdater(repo, null);
return mbr.preview(scope, repo.getArchives());

} catch (Exception e) {
Expand All @@ -260,7 +261,6 @@ private String preview(Scope scope) {

private void upgradeRevisions(Scope scope) {
try {
MbrUpdater mbr = new MbrUpdater(repo, null);

MultiMap<Archive, MavenVersion> updates = MbrUpdater.getUpdates(scope, Collections.singleton(repo),
repo.getArchives(), false);
Expand Down

0 comments on commit 2d1f949

Please sign in to comment.