Skip to content

Commit 7525f65

Browse files
committed
DevLauncher supports Maven settings.xml
AsyncCollection can receive an error add GUIDUtil fix ExtensionPoints
1 parent 2042710 commit 7525f65

File tree

17 files changed

+251
-43
lines changed

17 files changed

+251
-43
lines changed

core.javaee/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<attributes>
2222
<attribute name="optional" value="true"/>
2323
<attribute name="maven.pomderived" value="true"/>
24+
<attribute name="test" value="true"/>
2425
</attributes>
2526
</classpathentry>
2627
<classpathentry kind="output" path="target/classes"/>

core.javaee/.settings/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8+
org.eclipse.jdt.core.compiler.release=disabled
89
org.eclipse.jdt.core.compiler.source=1.8

net.lecousin.core/.classpath

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<attributes>
1111
<attribute name="optional" value="true"/>
1212
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
1314
</attributes>
1415
</classpathentry>
1516
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
@@ -42,6 +43,7 @@
4243
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
4344
<attributes>
4445
<attribute name="maven.pomderived" value="true"/>
46+
<attribute name="test" value="true"/>
4547
</attributes>
4648
</classpathentry>
4749
<classpathentry kind="output" path="target/classes"/>

net.lecousin.core/.settings/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8+
org.eclipse.jdt.core.compiler.release=disabled
89
org.eclipse.jdt.core.compiler.source=1.8

net.lecousin.core/src/main/java/net/lecousin/framework/application/LCCore.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,8 @@ public static synchronized void start() {
8888
started = true;
8989

9090
// init logging system if not specified
91-
if (System.getProperty("org.apache.commons.logging.Log") == null) {
92-
try {
93-
LCCore.class.getClassLoader().loadClass("net.lecousin.framework.log.bridges.ApacheCommonsLogging");
94-
System.setProperty("org.apache.commons.logging.Log", "net.lecousin.framework.log.bridges.ApacheCommonsLogging");
95-
} catch (Throwable t) { /* ignore */ }
96-
}
91+
if (System.getProperty("org.apache.commons.logging.Log") == null)
92+
System.setProperty("org.apache.commons.logging.Log", "net.lecousin.framework.log.bridges.ApacheCommonsLogging");
9793

9894
// register protocols
9995
String protocols = System.getProperty("java.protocol.handler.pkgs");

net.lecousin.core/src/main/java/net/lecousin/framework/application/launcher/AppLauncher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ else if (args[i].startsWith("-maven-repository=")) {
9494
pomLoader.addRepository(repo);
9595
repositories.add(repo);
9696
}
97+
// TODO should we really use the local repository (and so we need to parse settings.xml), or it should be given ?
9798

9899
// load configuration file
99100
File cfgFile = null;

net.lecousin.core/src/main/java/net/lecousin/framework/application/launcher/DevLauncher.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.lecousin.framework.application.libraries.artifacts.LibraryDescriptorLoader;
1717
import net.lecousin.framework.application.libraries.artifacts.maven.MavenLocalRepository;
1818
import net.lecousin.framework.application.libraries.artifacts.maven.MavenPOMLoader;
19+
import net.lecousin.framework.application.libraries.artifacts.maven.MavenSettings;
1920
import net.lecousin.framework.concurrent.Task;
2021
import net.lecousin.framework.concurrent.synch.ISynchronizationPoint;
2122
import net.lecousin.framework.util.Triple;
@@ -95,6 +96,7 @@ else if (args[i].startsWith("-maven-repository=")) {
9596
else if (projects == null) System.err.println("Missing projects parameter in command line");
9697
else stop = false;
9798
if (stop) {
99+
printUsage();
98100
LCCore.stop(true);
99101
return;
100102
}
@@ -119,7 +121,19 @@ else if (args[i].startsWith("-maven-repository=")) {
119121
File appDir = cfgFile.getParentFile();
120122

121123
// add local maven repository
122-
File dir = new File(System.getProperty("user.home") + "/.m2/repository");
124+
File settings = new File(System.getProperty("user.home") + "/.m2/settings.xml");
125+
String localRepo = System.getProperty("user.home") + "/.m2/repository";
126+
if (settings.exists()) {
127+
try {
128+
MavenSettings ms = MavenSettings.load(settings);
129+
if (ms.localRepository != null)
130+
localRepo = ms.localRepository;
131+
} catch (Exception e) {
132+
System.err.println("Error reading Maven settings.xml");
133+
e.printStackTrace(System.err);
134+
}
135+
}
136+
File dir = new File(localRepo);
123137
if (dir.exists())
124138
pomLoader.addRepository(new MavenLocalRepository(dir, true, true));
125139

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package net.lecousin.framework.application.libraries.artifacts.maven;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.InputStream;
6+
import java.util.ArrayList;
7+
8+
import javax.xml.stream.XMLInputFactory;
9+
import javax.xml.stream.XMLStreamConstants;
10+
import javax.xml.stream.XMLStreamReader;
11+
12+
public class MavenSettings {
13+
14+
public String localRepository = null;
15+
public ArrayList<String> activeProfiles = new ArrayList<>();
16+
17+
public static MavenSettings load(File file) throws Exception {
18+
try (FileInputStream input = new FileInputStream(file)) {
19+
return load(input);
20+
}
21+
}
22+
23+
public static MavenSettings load(InputStream input) throws Exception {
24+
XMLStreamReader xml = XMLInputFactory.newFactory().createXMLStreamReader(input);
25+
while (xml.hasNext()) {
26+
xml.next();
27+
if (xml.getEventType() == XMLStreamConstants.START_ELEMENT) {
28+
if (!"settings".equals(xml.getLocalName()))
29+
throw new Exception("Root element of a Maven settings.xml file must be <settings>");
30+
MavenSettings settings = new MavenSettings();
31+
while (xml.hasNext()) {
32+
xml.next();
33+
if (xml.getEventType() == XMLStreamConstants.START_ELEMENT) {
34+
if ("localRepository".equals(xml.getLocalName())) {
35+
settings.localRepository = xml.getElementText().trim();
36+
} else if ("activeProfiles".equals(xml.getLocalName())) {
37+
while (xml.hasNext()) {
38+
xml.next();
39+
if (xml.getEventType() == XMLStreamConstants.START_ELEMENT) {
40+
if ("activeProfile".equals(xml.getLocalName()))
41+
settings.activeProfiles.add(xml.getElementText().trim());
42+
} else if (xml.getEventType() == XMLStreamConstants.END_ELEMENT)
43+
break;
44+
}
45+
}
46+
} else if (xml.getEventType() == XMLStreamConstants.END_ELEMENT)
47+
break;
48+
}
49+
settings.activeProfiles.trimToSize();
50+
return settings;
51+
}
52+
}
53+
return new MavenSettings();
54+
}
55+
56+
}

net.lecousin.core/src/main/java/net/lecousin/framework/collections/AsyncCollection.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,35 @@ public interface AsyncCollection<T> {
1717
/** Called when new elements are ready. */
1818
public void newElements(Collection<T> elements);
1919

20-
/** Called when no more elements will come. */
20+
/** Called when no more elements will come, and no error was encountered. */
2121
public void done();
2222

2323
/** Return true if the method done has been called already. */
2424
public boolean isDone();
2525

26+
/** Called if an error occured before all elements have been retrieved. */
27+
public void error(Exception error);
28+
29+
/** Return true if the method error has been called. */
30+
public boolean hasError();
31+
2632
/**
2733
* Simple implementation with a listener on both operations: newElements and done.
2834
* @param <T> type of elements
2935
*/
3036
public static class Listen<T> implements AsyncCollection<T> {
3137
/** Constructor. */
32-
public Listen(Listener<Collection<T>> onElementsReady, Runnable onDone) {
38+
public Listen(Listener<Collection<T>> onElementsReady, Runnable onDone, Listener<Exception> onError) {
3339
this.onElementsReady = onElementsReady;
3440
this.onDone = onDone;
41+
this.onError = onError;
3542
}
3643

3744
private Listener<Collection<T>> onElementsReady;
3845
private Runnable onDone;
3946
private boolean isDone = false;
47+
private Listener<Exception> onError;
48+
private boolean hasError = false;
4049

4150
@Override
4251
public void newElements(Collection<T> elements) {
@@ -53,6 +62,17 @@ public void done() {
5362
public boolean isDone() {
5463
return isDone;
5564
}
65+
66+
@Override
67+
public void error(Exception error) {
68+
if (onError != null) onError.fire(error);
69+
hasError = true;
70+
}
71+
72+
@Override
73+
public boolean hasError() {
74+
return hasError;
75+
}
5676
}
5777

5878
/**
@@ -80,13 +100,23 @@ public synchronized void newElements(Collection<T> elements) {
80100

81101
@Override
82102
public synchronized void done() {
83-
if (--remainingDone == 0)
103+
if (--remainingDone == 0 && !collection.hasError())
84104
collection.done();
85105
}
86106

87107
@Override
88108
public boolean isDone() {
89-
return remainingDone == 0;
109+
return remainingDone == 0 && !collection.hasError();
110+
}
111+
112+
@Override
113+
public void error(Exception error) {
114+
collection.error(error);
115+
}
116+
117+
@Override
118+
public boolean hasError() {
119+
return collection.hasError();
90120
}
91121
}
92122

@@ -101,6 +131,9 @@ public static interface OneByOne<T> {
101131
/** Called when no more element will come. */
102132
public void done();
103133

134+
/** Called when an error occured while retrieving elements. */
135+
public void error(Exception error);
136+
104137
/** A refreshable collection is a collection that can be restarted, with new elements coming and replacing the previous ones.
105138
* @param <T> type of elements
106139
*/
@@ -116,8 +149,10 @@ public static interface Refreshable<T> extends OneByOne<T> {
116149
public static class Keep<T> implements AsyncCollection<T> {
117150
private LinkedArrayList<T> list = new LinkedArrayList<T>(10);
118151
private boolean done = false;
152+
private Exception error = null;
119153
private ArrayList<AsyncCollection<T>> listeners = new ArrayList<>(5);
120154
private ArrayList<Runnable> doneListeners = new ArrayList<>(2);
155+
private ArrayList<Listener<Exception>> errorListeners = new ArrayList<>(2);
121156

122157
@Override
123158
public void newElements(Collection<T> elements) {
@@ -161,6 +196,37 @@ public void ondone(Runnable listener) {
161196
listener.run();
162197
}
163198

199+
@Override
200+
public void error(Exception error) {
201+
synchronized (this) {
202+
this.error = error;
203+
}
204+
for (AsyncCollection<T> col : listeners)
205+
col.error(error);
206+
listeners = null;
207+
for (Listener<Exception> r : errorListeners)
208+
r.fire(error);
209+
errorListeners = null;
210+
}
211+
212+
@Override
213+
public boolean hasError() {
214+
return error != null;
215+
}
216+
217+
/** Add a listener to be called when the error method is called.
218+
* If the error method has been already called, the listener is immediately called.
219+
*/
220+
public void onerror(Listener<Exception> listener) {
221+
synchronized (this) {
222+
if (error == null) {
223+
errorListeners.add(listener);
224+
return;
225+
}
226+
}
227+
listener.fire(error);
228+
}
229+
164230
/** Send the elements of this collection to the given collection.
165231
* All elements already present in this collection are immediately given by calling the method newElements.
166232
* If the method done has been called already on this collection, the method done is also called
@@ -169,7 +235,7 @@ public void ondone(Runnable listener) {
169235
public void provideTo(AsyncCollection<T> col) {
170236
ArrayList<T> already = null;
171237
synchronized (this) {
172-
if (!done) {
238+
if (!done && error == null) {
173239
already = new ArrayList<>(list);
174240
listeners.add(col);
175241
}
@@ -179,7 +245,10 @@ public void provideTo(AsyncCollection<T> col) {
179245
return;
180246
}
181247
col.newElements(list);
182-
col.done();
248+
if (error == null)
249+
col.done();
250+
else
251+
col.error(error);
183252
}
184253

185254
/** Return the list containing the elements kept so far. */

net.lecousin.core/src/main/java/net/lecousin/framework/plugins/ExtensionPoint.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public interface ExtensionPoint<PluginClass extends Plugin> {
2525
default void printInfo(StringBuilder s) {
2626
s.append(getClass().getName()).append(":");
2727
for (PluginClass pi : getPlugins()) {
28-
s.append("\r\n\t- ").append(pi.getClass().getName());
28+
if (pi != null)
29+
s.append("\r\n\t- ").append(pi.getClass().getName());
30+
else
31+
s.append("\r\n\tNULL !!!");
2932
}
3033
}
3134

0 commit comments

Comments
 (0)