Skip to content

Commit

Permalink
Improves and harmonizes the console messages at the launch
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Jun 18, 2021
1 parent 20f59fc commit 2ab03ee
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 69 deletions.
67 changes: 34 additions & 33 deletions msi.gama.core/src/msi/gaml/compilation/kernel/GamaBundleLoader.java
Expand Up @@ -94,9 +94,9 @@ public static void ERROR(final Exception e) {
public static final String SYS_JAVA = System.getProperty("java.version");

public static void preBuildContributions() throws Exception {
DEBUG.LOG(DEBUG.PAD("> GAMA " + GAMA.VERSION_NUMBER + " loading ", 45, '.') + " system " + SYS_NAME + " "
+ SYS_VERS + ", " + SYS_ARCH + ", JDK " + SYS_JAVA);
DEBUG.TIMER("> GAMA total load time.......................................", () -> {
DEBUG.LOG(DEBUG.PAD("> GAMA: version " + GAMA.VERSION_NUMBER, 45, ' ') + DEBUG.PAD(" loading on", 15, '_') + " "
+ SYS_NAME + " " + SYS_VERS + ", " + SYS_ARCH + ", JDK " + SYS_JAVA);
DEBUG.TIMER(DEBUG.PAD("> GAMA: all plugins", 45, ' ') + DEBUG.PAD(" loaded in", 15, '_'), () -> {
final IExtensionRegistry registry = Platform.getExtensionRegistry();
// We retrieve the elements declared as extensions to the GAML language,
// either with the new or the deprecated extension
Expand Down Expand Up @@ -222,41 +222,42 @@ public static void preBuildContributions() throws Exception {

@SuppressWarnings ("unchecked")
public static void preBuild(final Bundle bundle) throws Exception {
TIMER_WITH_EXCEPTIONS(PAD("> GAMA: " + bundle.getSymbolicName(), 45, '.') + " loaded in......", () -> {
String shortcut = bundle.getSymbolicName();
shortcut = shortcut.substring(shortcut.lastIndexOf('.') + 1);
GamaClassLoader.getInstance().addBundle(bundle);
Class<IGamlAdditions> gamlAdditions = null;
try {
// gamlAdditions = (Class<IGamlAdditions>) bundle.loadClass(ADDITIONS);
TIMER_WITH_EXCEPTIONS(PAD("> GAMA: " + bundle.getSymbolicName(), 45, ' ') + DEBUG.PAD(" loaded in", 15, '_'),
() -> {
String shortcut = bundle.getSymbolicName();
shortcut = shortcut.substring(shortcut.lastIndexOf('.') + 1);
GamaClassLoader.getInstance().addBundle(bundle);
Class<IGamlAdditions> gamlAdditions = null;
try {
// gamlAdditions = (Class<IGamlAdditions>) bundle.loadClass(ADDITIONS);

gamlAdditions = (Class<IGamlAdditions>) bundle
.loadClass(ADDITIONS_PACKAGE_BASE + "." + shortcut + "." + ADDITIONS_CLASS_NAME);
gamlAdditions = (Class<IGamlAdditions>) bundle
.loadClass(ADDITIONS_PACKAGE_BASE + "." + shortcut + "." + ADDITIONS_CLASS_NAME);

} catch (final ClassNotFoundException e1) {
ERR(">> Impossible to load additions from " + bundle.toString() + " because of " + e1);
throw e1;
} catch (final ClassNotFoundException e1) {
ERR(">> Impossible to load additions from " + bundle.toString() + " because of " + e1);
throw e1;

}
}

IGamlAdditions add = null;
try {
add = gamlAdditions.newInstance();
} catch (final InstantiationException e) {
ERR(">> Impossible to instantiate additions from " + bundle);
throw e;
} catch (final IllegalAccessException e) {
ERR(">> Impossible to access additions from " + bundle);
throw e;
}
try {
add.initialize();
} catch (final SecurityException | NoSuchMethodException e) {
ERR(">> Impossible to instantiate additions from " + bundle);
throw e;
}
IGamlAdditions add = null;
try {
add = gamlAdditions.newInstance();
} catch (final InstantiationException e) {
ERR(">> Impossible to instantiate additions from " + bundle);
throw e;
} catch (final IllegalAccessException e) {
ERR(">> Impossible to access additions from " + bundle);
throw e;
}
try {
add.initialize();
} catch (final SecurityException | NoSuchMethodException e) {
ERR(">> Impossible to instantiate additions from " + bundle);
throw e;
}

});
});
}

/**
Expand Down
11 changes: 5 additions & 6 deletions msi.gama.ext/src/msi/gama/ext/Activator.java
Expand Up @@ -12,8 +12,6 @@
**********************************************************************************************/
package msi.gama.ext;

import java.util.Arrays;

import javax.imageio.ImageIO;
import javax.media.jai.JAI;

Expand All @@ -25,6 +23,7 @@
import org.osgi.framework.BundleContext;

import it.geosolutions.jaiext.ConcurrentOperationRegistry;
import one.util.streamex.StreamEx;

public class Activator implements BundleActivator {

Expand Down Expand Up @@ -65,8 +64,8 @@ public void start(final BundleContext bundleContext) throws Exception {
//
// // }

System.out.println(
PAD("> JAI/ImageIO subsystem ", 45) + " loaded for " + Arrays.asList(ImageIO.getReaderFileSuffixes()));
System.out.println(PAD("> JAI : ImageIO extensions", 45, ' ') + PAD(" loaded for", 15, '_') + " "
+ StreamEx.of(ImageIO.getReaderFileSuffixes()).joining("|"));
}

/*
Expand All @@ -79,12 +78,12 @@ public void stop(final BundleContext bundleContext) throws Exception {
Activator.context = null;
}

public static String PAD(final String string, final int minLength) {
public static String PAD(final String string, final int minLength, final char pad) {
if (string.length() >= minLength) return string;
final StringBuilder sb = new StringBuilder(minLength);
sb.append(string);
for (int i = string.length(); i < minLength; i++) {
sb.append('.');
sb.append(pad);
}
return sb.toString();
}
Expand Down
Expand Up @@ -129,7 +129,7 @@ public boolean isEmpty() {
public boolean containsKey(final Object key) {
for (int i = 0; i < contents.length; i += 2) {
final String k = contents[i];
if (k.equals(key)) { return true; }
if (k.equals(key)) return true;
}
return false;
}
Expand All @@ -143,7 +143,7 @@ public boolean containsKey(final Object key) {
public boolean containsValue(final Object value) {
for (int i = 1; i < contents.length; i += 2) {
final String k = contents[i];
if (k.equals(value)) { return true; }
if (k.equals(value)) return true;
}
return false;

Expand All @@ -158,7 +158,7 @@ public boolean containsValue(final Object value) {
public String get(final Object key) {
for (int i = 0; i < contents.length; i += 2) {
final String k = contents[i];
if (k.equals(key)) { return contents[i + 1]; }
if (k.equals(key)) return contents[i + 1];
}
return null;

Expand Down Expand Up @@ -266,12 +266,11 @@ public Set<java.util.Map.Entry<String, String>> entrySet() {
while (!GamaMetaModel.INSTANCE.isInitialized) {
try {
Thread.sleep(100);
// DEBUG.OUT("> GAMA: Waiting for GAML artefacts to build");
} catch (final InterruptedException e) {
e.printStackTrace();
}
}
DEBUG.TIMER("> GAMA building GAML artefacts in ", () -> {
DEBUG.TIMER(DEBUG.PAD("> GAMA: GAML artefacts", 45, ' ') + DEBUG.PAD(" built in", 15, '_'), () -> {
IUnits.initialize();
createDescriptions();
});
Expand All @@ -280,10 +279,7 @@ public Set<java.util.Map.Entry<String, String>> entrySet() {

static Resource createResource(final String uri) {
Resource r = rs.getResource(URI.createURI(uri, false), false);
if (r == null) {
r = rs.createResource(URI.createURI(uri, false));
}
// DescriptionFactory.documentResource(r);
if (r == null) { r = rs.createResource(URI.createURI(uri, false)); }
return r;
}

Expand Down Expand Up @@ -416,11 +412,9 @@ public IMap<QualifiedName, IEObjectDescription> getEObjectDescriptions(final ECl
}

public TerminalMapBasedScope getGlobalScope(final EClass eClass) {
if (GLOBAL_SCOPES.containsKey(eClass)) { return GLOBAL_SCOPES.get(eClass); }
if (GLOBAL_SCOPES.containsKey(eClass)) return GLOBAL_SCOPES.get(eClass);
IMap<QualifiedName, IEObjectDescription> descriptions = getEObjectDescriptions(eClass);
if (descriptions == null) {
descriptions = EMPTY_MAP;
}
if (descriptions == null) { descriptions = EMPTY_MAP; }
final TerminalMapBasedScope result = new TerminalMapBasedScope(descriptions);
GLOBAL_SCOPES.put(eClass, result);
return result;
Expand All @@ -445,9 +439,7 @@ public static void createDescriptions() {
for (final OperatorProto t : AbstractGamlAdditions.getAllFields()) {
addVar(t.getName(), t, "field");
}
if (!GAMA.isInHeadLessMode()) {
addVar(IKeyword.GAMA, GAMA.getPlatformAgent(), "platform");
}
if (!GAMA.isInHeadLessMode()) { addVar(IKeyword.GAMA, GAMA.getPlatformAgent(), "platform"); }
for (final IDescription t : AbstractGamlAdditions.getAllVars()) {
addVar(t.getName(), t, "variable");
}
Expand Down Expand Up @@ -490,7 +482,7 @@ protected IScope getScope(final Resource resource, final boolean ignoreCase, fin
final Predicate<IEObjectDescription> filter) {
IScope scope = getGlobalScope(type);
final Collection<URI> uniqueImportURIs = getAllImportedURIs(resource, resource.getResourceSet()).keySet();
if (uniqueImportURIs.size() == 1) { return scope; }
if (uniqueImportURIs.size() == 1) return scope;
final List<URI> urisAsList = Lists.newArrayList(uniqueImportURIs);
urisAsList.remove(resource.getURI());
Collections.reverse(urisAsList);
Expand All @@ -500,7 +492,7 @@ protected IScope getScope(final Resource resource, final boolean ignoreCase, fin
}

public static IEObjectDescription getVar(final String name) {
if (name == null) { return null; }
if (name == null) return null;
return descriptions.get(eVar).get(QualifiedName.create(name));
}

Expand Down
Expand Up @@ -22,17 +22,18 @@ public class BulletActivator implements BundleActivator {
public void start(final BundleContext context) throws Exception {

if (LOAD_NATIVE_BULLET_LIBRARY) {
TIMER_WITH_EXCEPTIONS(PAD("> GAMA: native Bullet library", 45, '.') + " loaded in......", () -> {
try {
System.loadLibrary("bulletjme");
NATIVE_BULLET_LIBRARY_LOADED = true;
} catch (Exception e) {
ERR(">> Impossible to load Bullet native library from " + context.getBundle().getSymbolicName()
+ " because of " + e.getMessage());
ERR(">> GAMA will revert to JBullet instead");
throw e;
}
});
TIMER_WITH_EXCEPTIONS(PAD("> GAMA: native Bullet library", 45, ' ') + DEBUG.PAD(" loaded in", 15, '_'),
() -> {
try {
System.loadLibrary("bulletjme");
NATIVE_BULLET_LIBRARY_LOADED = true;
} catch (Exception e) {
ERR(">> Impossible to load Bullet native library from "
+ context.getBundle().getSymbolicName() + " because of " + e.getMessage());
ERR(">> GAMA will revert to JBullet instead");
throw e;
}
});

}
}
Expand Down
Expand Up @@ -95,7 +95,7 @@
public class SwtGui implements IGui {

static {
DEBUG.ON();
DEBUG.OFF();
}

public volatile static boolean ALL_TESTS_RUNNING;
Expand Down

0 comments on commit 2ab03ee

Please sign in to comment.