From: Mathieu Baudier Date: Sun, 16 Feb 2020 08:09:30 +0000 (+0100) Subject: Improve logging in SLC Repo layer. X-Git-Tag: argeo-slc-2.1.17~64 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=3b8a833c8df0b5cd0ee4992a9185aa25faaf015a;p=gpl%2Fargeo-slc.git Improve logging in SLC Repo layer. --- diff --git a/org.argeo.slc.api/src/org/argeo/slc/DefaultCategorizedNameVersion.java b/org.argeo.slc.api/src/org/argeo/slc/DefaultCategorizedNameVersion.java new file mode 100644 index 000000000..a30970e45 --- /dev/null +++ b/org.argeo.slc.api/src/org/argeo/slc/DefaultCategorizedNameVersion.java @@ -0,0 +1,34 @@ +package org.argeo.slc; + +/** Canonical implementation of {@link CategorizedNameVersion} */ +public class DefaultCategorizedNameVersion extends DefaultNameVersion implements CategorizedNameVersion { + private String category; + + public DefaultCategorizedNameVersion() { + } + + public DefaultCategorizedNameVersion(String category, String name, String version) { + super(name, version); + this.category = category; + } + + public DefaultCategorizedNameVersion(String category, NameVersion nameVersion) { + super(nameVersion); + this.category = category; + } + + @Override + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + @Override + public String toString() { + return category + ":" + super.toString(); + } + +} diff --git a/org.argeo.slc.api/src/org/argeo/slc/DefaultNameVersion.java b/org.argeo.slc.api/src/org/argeo/slc/DefaultNameVersion.java index 97e579ff8..bd64198f0 100644 --- a/org.argeo.slc.api/src/org/argeo/slc/DefaultNameVersion.java +++ b/org.argeo.slc.api/src/org/argeo/slc/DefaultNameVersion.java @@ -75,7 +75,7 @@ public class DefaultNameVersion implements NameVersion, @Override public int hashCode() { - return name.hashCode() + version.hashCode(); + return name.hashCode(); } @Override diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java index d89077322..adb591bbe 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/ModularDistributionIndexer.java @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; import org.argeo.slc.CategorizedNameVersion; -import org.argeo.slc.DefaultNameVersion; +import org.argeo.slc.DefaultCategorizedNameVersion; import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; import org.argeo.slc.SlcNames; @@ -169,7 +169,7 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames { st.nextToken(); // moduleVersion String relativeUrl = st.nextToken(); Artifact currModule = AetherUtils.convertPathToArtifact(relativeUrl, null); - modules.add(new MyCategorizedNameVersion(currModule.getGroupId(), currModule.getArtifactId(), + modules.add(new DefaultCategorizedNameVersion(currModule.getGroupId(), currModule.getArtifactId(), currModule.getVersion())); } return new MyModularDistribution(distribution, modules); @@ -181,20 +181,6 @@ public class ModularDistributionIndexer implements NodeIndexer, SlcNames { } } - /** The created modular distribution */ - private static class MyCategorizedNameVersion extends DefaultNameVersion implements CategorizedNameVersion { - private final String category; - - public MyCategorizedNameVersion(String category, String name, String version) { - super(name, version); - this.category = category; - } - - public String getCategory() { - return category; - } - } - /** * A consistent and versioned OSGi distribution, which can be built and tested. */ diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java index b47da8b88..7d7485604 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java @@ -15,11 +15,11 @@ import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.repo.ArgeoOsgiDistribution; import org.argeo.slc.repo.ArtifactDistribution; -/** A consistent and versioned OSGi distribution, which can be built and tested. */ -public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements - ArgeoOsgiDistribution { - private final static Log log = LogFactory - .getLog(ArgeoOsgiDistributionImpl.class); +/** + * A consistent and versioned OSGi distribution, which can be built and tested. + */ +public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements ArgeoOsgiDistribution { + private final static Log log = LogFactory.getLog(ArgeoOsgiDistributionImpl.class); private List modules = new ArrayList(); @@ -28,45 +28,38 @@ public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements } public void init() { - if (log.isDebugEnabled()) { - SortedSet sort = new TreeSet(); - Iterator nvIt = nameVersions(); - while (nvIt.hasNext()) { - NameVersion nv = nvIt.next(); - sort.add(nv.getName() + ":" + nv.getVersion()); - } + if (log.isDebugEnabled()) + log.debug(describe()); + } - StringBuffer buf = new StringBuffer( - "## OSGi FACTORY MANAGED MODULES : \n"); - for (String str : sort) { - buf.append(str).append('\n'); - } + public void destroy() { - log.debug(buf); - } } - // private static void print(ModuleSet moduleSet, Integer depth) { - // StringBuilder prefix = new StringBuilder(); - // for (int i = 0; i < depth; i++) { - // prefix.append(' '); - // } - // String p = prefix.toString(); - // prefix.setLength(0); - // log.debug(p + "## " + moduleSet.toString()); - // Iterator nvIt = moduleSet.nameVersions(); - // while (nvIt.hasNext()) { - // NameVersion nv = nvIt.next(); - // if (nv instanceof ModuleSet) - // print((ModuleSet) nv, depth + 1); - // else - // log.debug(p + nv); - // - // } - // } - - public void destroy() { + public String describe() { + SortedSet sort = new TreeSet(); + Iterator nvIt = nameVersions(); + while (nvIt.hasNext()) { + NameVersion nv = nvIt.next(); + String str = nv.toString(); + if (nv instanceof MavenWrapper) + str = str + "\t(Maven)"; + else if (nv instanceof UriWrapper) + str = str + "\t(URI)"; + else if (nv instanceof OsgiCategorizedNV) + str = str + "\t(OSGi from archive)"; + else if (nv instanceof BndWrapper) + str = str + "\t(Plain BND from archive)"; + else + str = str + "\t(UNKNOWN??)"; + sort.add(str); + } + StringBuffer buf = new StringBuffer("## DISTRIBUTION " + toString() + " ##\n"); + for (String str : sort) { + buf.append(str).append('\n'); + } + return buf.toString(); } public Iterator nameVersions() { @@ -74,23 +67,12 @@ public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements for (Object module : modules) { // extract runnable from execution flow if (module instanceof ExecutionFlow) { - for (Iterator it = ((ExecutionFlow) module) - .runnables(); it.hasNext();) { + for (Iterator it = ((ExecutionFlow) module).runnables(); it.hasNext();) { processModule(nameVersions, it.next()); } - } - // module = ((ExecutionFlow) module).getRunnable(); - else { + } else { processModule(nameVersions, module); } - // if (module instanceof ModuleSet) - // addNameVersions(nameVersions, (ModuleSet) module); - // else if (module instanceof NameVersion) { - // NameVersion nv = (NameVersion) module; - // if (!nameVersions.contains(nv)) - // nameVersions.add(nv); - // } else - // log.warn("Ignored " + module); } return nameVersions.iterator(); } @@ -100,37 +82,32 @@ public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements addNameVersions(nameVersions, (ModuleSet) module); else if (module instanceof NameVersion) { NameVersion nv = (NameVersion) module; - if (!nameVersions.contains(nv)) - nameVersions.add(nv); + addNameVersion(nameVersions, nv); } else log.warn("Ignored " + module); } - private void addNameVersions(List nameVersions, - ModuleSet moduleSet) { + private void addNameVersions(List nameVersions, ModuleSet moduleSet) { Iterator it = moduleSet.nameVersions(); while (it.hasNext()) { NameVersion nv = it.next(); - if (!nameVersions.contains(nv)) - nameVersions.add(nv); + addNameVersion(nameVersions, nv); + } + } + + protected void addNameVersion(List nameVersions, NameVersion nv) { + if (!nameVersions.contains(nv)) { + nameVersions.add(nv); } } // Modular distribution interface methods. Not yet used. - public Distribution getModuleDistribution(String moduleName, - String moduleVersion) { - // NameVersion searched = new DefaultNameVersion(moduleName, - // moduleVersion); - // for (Distribution ad : modules) { - // if (ad.equals(searched)) - // return ad; - // } - return null; + public Distribution getModuleDistribution(String moduleName, String moduleVersion) { + throw new UnsupportedOperationException(); } public Object getModulesDescriptor(String descriptorType) { - // TODO Auto-generated method stub - return null; + throw new UnsupportedOperationException(); } /* DEPENDENCY INJECTION */ diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java index 56dda5bdf..e11f7c130 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/BndWrapper.java @@ -23,8 +23,7 @@ import aQute.bnd.osgi.Constants; import aQute.bnd.osgi.Jar; /** Utilities around the BND library, which manipulates OSGi metadata. */ -public class BndWrapper implements Constants, CategorizedNameVersion, - Distribution, BeanNameAware { +public class BndWrapper implements Constants, CategorizedNameVersion, Distribution, BeanNameAware { private final static Log log = LogFactory.getLog(BndWrapper.class); private String groupId; @@ -50,18 +49,13 @@ public class BndWrapper implements Constants, CategorizedNameVersion, Version versionToUse; if (sourceManifest != null) { // Symbolic name - String sourceSymbolicName = sourceManifest.getMainAttributes() - .getValue(BUNDLE_SYMBOLICNAME); - if (sourceSymbolicName != null - && !sourceSymbolicName.equals(name)) - log.info("The new symbolic name (" - + name - + ") is not consistant with the wrapped bundle symbolic name (" - + sourceSymbolicName + ")"); + String sourceSymbolicName = sourceManifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + if (sourceSymbolicName != null && !sourceSymbolicName.equals(name)) + log.info("The new symbolic name (" + name + + ") is not consistant with the wrapped bundle symbolic name (" + sourceSymbolicName + ")"); // Version - String sourceVersion = sourceManifest.getMainAttributes() - .getValue(BUNDLE_VERSION); + String sourceVersion = sourceManifest.getMainAttributes().getValue(BUNDLE_VERSION); if (getVersion() == null && sourceVersion == null) { throw new SlcException("A bundle version must be defined."); } else if (getVersion() == null && sourceVersion != null) { @@ -72,13 +66,10 @@ public class BndWrapper implements Constants, CategorizedNameVersion, } else {// both set versionToUse = new Version(getVersion()); Version sv = new Version(sourceVersion); - if (versionToUse.getMajor() != sv.getMajor() - || versionToUse.getMinor() != sv.getMinor() + if (versionToUse.getMajor() != sv.getMajor() || versionToUse.getMinor() != sv.getMinor() || versionToUse.getMicro() != sv.getMicro()) { - log.warn("The new version (" - + versionToUse - + ") is not consistant with the wrapped bundle version (" - + sv + ")"); + log.warn("The new version (" + versionToUse + + ") is not consistant with the wrapped bundle version (" + sv + ")"); } } } else { @@ -99,11 +90,9 @@ public class BndWrapper implements Constants, CategorizedNameVersion, if (license != null) { StringBuilder sb = new StringBuilder(license.getUri()); if (license.getName() != null) - sb.append(';').append("description=") - .append(license.getName()); + sb.append(';').append("description=").append(license.getName()); if (license.getLink() != null) - sb.append(';').append("link=") - .append(license.getLink()); + sb.append(';').append("link=").append(license.getLink()); properties.setProperty(BUNDLE_LICENSE, sb.toString()); // TODO add LICENSE.TXT } else { @@ -155,8 +144,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion, public void setVersion(String version) { if (this.version != null) - throw new SlcException("Version already set on " + name + " (" - + this.version + ")"); + throw new SlcException("Version already set on " + name + " (" + this.version + ")"); this.version = version; } @@ -187,8 +175,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion, this.name = name; } else { if (!name.contains("#")) - log.warn("Using explicitely set name " + this.name - + " and not bean name " + name); + log.warn("Using explicitely set name " + this.name + " and not bean name " + name); } } @@ -205,7 +192,7 @@ public class BndWrapper implements Constants, CategorizedNameVersion, } public String getDistributionId() { - return getArtifact().toString(); + return getCategory() + ":" + getName() + ":" + getVersion(); } public Artifact getArtifact() { @@ -214,20 +201,21 @@ public class BndWrapper implements Constants, CategorizedNameVersion, @Override public String toString() { - return getArtifact().toString(); + return getDistributionId(); } @Override public int hashCode() { - return getArtifact().hashCode(); + if (name != null) + return name.hashCode(); + return super.hashCode(); } @Override public boolean equals(Object obj) { if (obj instanceof CategorizedNameVersion) { CategorizedNameVersion cnv = (CategorizedNameVersion) obj; - return getCategory().equals(cnv.getCategory()) - && getName().equals(cnv.getName()) + return getCategory().equals(cnv.getCategory()) && getName().equals(cnv.getName()) && getVersion().equals(cnv.getVersion()); } else return false; diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/OsgiCategorizedNV.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/OsgiCategorizedNV.java index 0d75d2520..250149b09 100644 --- a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/OsgiCategorizedNV.java +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/OsgiCategorizedNV.java @@ -1,25 +1,17 @@ package org.argeo.slc.repo.osgi; -import org.argeo.slc.CategorizedNameVersion; -import org.argeo.slc.DefaultNameVersion; +import org.argeo.slc.DefaultCategorizedNameVersion; -class OsgiCategorizedNV extends DefaultNameVersion implements - CategorizedNameVersion, Runnable { - private String category; +/** */ +class OsgiCategorizedNV extends DefaultCategorizedNameVersion implements Runnable { /** Build runnable */ private Runnable build; - public OsgiCategorizedNV(String category, String name, String version, - Runnable build) { - super(name, version); - this.category = category; + public OsgiCategorizedNV(String category, String name, String version, Runnable build) { + super(category, name, version); this.build = build; } - public String getCategory() { - return category; - } - @Override public void run() { if (build != null)