Skip to content

Commit a00c62a

Browse files
Enable Spotless verification for Android Port and improve reporting
- Configured `spotless-maven-plugin` in `maven/android/pom.xml` to check `Ports/Android/src`. - Updated `scripts/build-android-port.sh` to run `spotless:check` and report results. - Applied Spotless formatting to existing Android port source code. - Updated quality reporting scripts to suppress missing report warnings and include Spotless results in the Android status comment. - Ensured CI fails if Spotless verification fails.
1 parent b1d6a59 commit a00c62a

File tree

58 files changed

+28526
-26121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+28526
-26121
lines changed

Ports/Android/src/com/codename1/impl/CodenameOneThread.java

Lines changed: 150 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
* published by the Free Software Foundation. Codename One designates this
77
* particular file as subject to the "Classpath" exception as provided
88
* by Oracle in the LICENSE file that accompanied this code.
9-
*
9+
*
1010
* This code is distributed in the hope that it will be useful, but WITHOUT
1111
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1313
* version 2 for more details (a copy is included in the LICENSE file that
1414
* accompanied this code).
15-
*
15+
*
1616
* You should have received a copy of the GNU General Public License version
1717
* 2 along with this work; if not, write to the Free Software Foundation,
1818
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19-
*
20-
* Please contact Codename One through http://www.codenameone.com/ if you
19+
*
20+
* Please contact Codename One through http://www.codenameone.com/ if you
2121
* need additional information or have any questions.
2222
*/
2323
package com.codename1.impl;
2424

2525
import com.codename1.io.Log;
26-
import com.codename1.io.Preferences;
2726
import com.codename1.io.Util;
2827
import com.codename1.system.CrashReport;
2928
import com.codename1.ui.Display;
@@ -40,166 +39,161 @@
4039
* @author Shai Almog
4140
*/
4241
public class CodenameOneThread extends Thread {
43-
private int[] stack = new int[500];
44-
private int stackPointer;
45-
private Runnable r;
46-
private static Class CODE = CodenameOneThread.class;
47-
private Hashtable exceptionStack = new Hashtable();
48-
public static int STACK_FRAME_SIZE = 65536;
49-
50-
/**
51-
* Constructor accepting the runnable
52-
*/
53-
public CodenameOneThread(final Runnable r, String threadName) {
54-
super(Thread.currentThread().getThreadGroup(), new Runnable() {
55-
/**
56-
* Catches exception
57-
*/
58-
public void run() {
59-
try {
60-
r.run();
61-
} catch(Throwable err) {
62-
err.printStackTrace();
63-
handleException(err);
64-
}
42+
private int[] stack = new int[500];
43+
private int stackPointer;
44+
private Runnable r;
45+
private static Class CODE = CodenameOneThread.class;
46+
private Hashtable exceptionStack = new Hashtable();
47+
public static int STACK_FRAME_SIZE = 65536;
48+
49+
/** Constructor accepting the runnable */
50+
public CodenameOneThread(final Runnable r, String threadName) {
51+
super(
52+
Thread.currentThread().getThreadGroup(),
53+
new Runnable() {
54+
/** Catches exception */
55+
public void run() {
56+
try {
57+
r.run();
58+
} catch (Throwable err) {
59+
err.printStackTrace();
60+
handleException(err);
6561
}
62+
}
63+
},
64+
threadName,
65+
STACK_FRAME_SIZE);
66+
this.r = r;
67+
}
6668

67-
}, threadName, STACK_FRAME_SIZE);
68-
this.r = r;
69-
}
70-
71-
public boolean hasStackFrame() {
72-
return stackPointer > 0;
73-
}
74-
75-
/**
76-
* Pushes a method id into the stack
77-
* @param method the method id
78-
*/
79-
public void pushStack(int method) {
80-
stack[stackPointer] = method;
81-
stackPointer++;
82-
}
83-
84-
/**
85-
* Pops the method stack pointer
86-
*/
87-
public void popStack() {
88-
stackPointer--;
89-
}
90-
91-
/**
92-
* Pushes the method to the current thread stack
93-
*
94-
* @param method the method id
95-
*/
96-
public static void push(int method) {
97-
Thread t = Thread.currentThread();
98-
if(t.getClass() == CODE) {
99-
CodenameOneThread c = (CodenameOneThread)t;
100-
c.pushStack(method);
101-
}
69+
public boolean hasStackFrame() {
70+
return stackPointer > 0;
71+
}
72+
73+
/**
74+
* Pushes a method id into the stack
75+
*
76+
* @param method the method id
77+
*/
78+
public void pushStack(int method) {
79+
stack[stackPointer] = method;
80+
stackPointer++;
81+
}
82+
83+
/** Pops the method stack pointer */
84+
public void popStack() {
85+
stackPointer--;
86+
}
87+
88+
/**
89+
* Pushes the method to the current thread stack
90+
*
91+
* @param method the method id
92+
*/
93+
public static void push(int method) {
94+
Thread t = Thread.currentThread();
95+
if (t.getClass() == CODE) {
96+
CodenameOneThread c = (CodenameOneThread) t;
97+
c.pushStack(method);
10298
}
99+
}
103100

104-
/**
105-
* Pops the current method from the stack
106-
*/
107-
public static void pop() {
108-
Thread t = Thread.currentThread();
109-
if(t.getClass() == CODE) {
110-
CodenameOneThread c = (CodenameOneThread)t;
111-
c.popStack();
112-
}
101+
/** Pops the current method from the stack */
102+
public static void pop() {
103+
Thread t = Thread.currentThread();
104+
if (t.getClass() == CODE) {
105+
CodenameOneThread c = (CodenameOneThread) t;
106+
c.popStack();
113107
}
114-
115-
116-
/**
117-
* Stores the stack for the given exception
118-
* @param t the exception mapping to the given stack
119-
*/
120-
public void storeStackForException(Throwable t, int currentStackFrame) {
121-
if(!exceptionStack.containsKey(t)) {
122-
int[] s = new int[stackPointer + 1];
123-
System.arraycopy(stack, 0, s, 0, stackPointer);
124-
s[stackPointer] = currentStackFrame;
125-
exceptionStack.put(t, s);
126-
}
108+
}
109+
110+
/**
111+
* Stores the stack for the given exception
112+
*
113+
* @param t the exception mapping to the given stack
114+
*/
115+
public void storeStackForException(Throwable t, int currentStackFrame) {
116+
if (!exceptionStack.containsKey(t)) {
117+
int[] s = new int[stackPointer + 1];
118+
System.arraycopy(stack, 0, s, 0, stackPointer);
119+
s[stackPointer] = currentStackFrame;
120+
exceptionStack.put(t, s);
127121
}
128-
129-
/**
130-
* Stores the stack for the given exception
131-
* @param th the exception mapping to the given stack
132-
*/
133-
public static void storeStack(Throwable th, int currentStackFrame) {
134-
Thread t = Thread.currentThread();
135-
if(t.getClass() == CODE) {
136-
CodenameOneThread c = (CodenameOneThread)t;
137-
c.storeStackForException(th, currentStackFrame);
138-
}
122+
}
123+
124+
/**
125+
* Stores the stack for the given exception
126+
*
127+
* @param th the exception mapping to the given stack
128+
*/
129+
public static void storeStack(Throwable th, int currentStackFrame) {
130+
Thread t = Thread.currentThread();
131+
if (t.getClass() == CODE) {
132+
CodenameOneThread c = (CodenameOneThread) t;
133+
c.storeStackForException(th, currentStackFrame);
139134
}
140-
141-
/**
142-
* Prints the stack trace matching the given stack
143-
*/
144-
public String getStack(Throwable t) {
145-
try {
146-
StringBuffer b = new StringBuffer();
147-
int size;
148-
int[] s = (int[])exceptionStack.get(t);
149-
if(s == null) {
150-
s = stack;
151-
size = stackPointer;
152-
} else {
153-
size = s.length;
154-
}
155-
String[] stk = new String[size];
156-
157-
InputStream inp = Display.getInstance().getResourceAsStream(getClass(), "/methodData.dat");
158-
if(inp == null) {
159-
StringWriter sw = new StringWriter();
160-
PrintWriter pw = new PrintWriter(sw);
161-
t.printStackTrace(pw);
162-
String str = sw.toString();
163-
Util.cleanup(sw);
164-
return str;
165-
}
166-
DataInputStream di = new DataInputStream(inp);
167-
int totalAmount = di.readInt();
168-
String lastClass = "";
169-
for(int x = 0 ; x < totalAmount ; x++) {
170-
String current = di.readUTF();
171-
if(current.indexOf('.') > -1) {
172-
lastClass = current;
173-
} else {
174-
for(int iter = 0 ; iter < size ; iter++) {
175-
if(s[iter] == x + 1) {
176-
stk[iter] = lastClass + "." + current;
177-
}
178-
}
179-
}
180-
}
181-
for(int iter = size - 1 ; iter >= 0 ; iter--) {
182-
b.append("at ");
183-
b.append(stk[iter]);
184-
b.append("\n");
135+
}
136+
137+
/** Prints the stack trace matching the given stack */
138+
public String getStack(Throwable t) {
139+
try {
140+
StringBuffer b = new StringBuffer();
141+
int size;
142+
int[] s = (int[]) exceptionStack.get(t);
143+
if (s == null) {
144+
s = stack;
145+
size = stackPointer;
146+
} else {
147+
size = s.length;
148+
}
149+
String[] stk = new String[size];
150+
151+
InputStream inp = Display.getInstance().getResourceAsStream(getClass(), "/methodData.dat");
152+
if (inp == null) {
153+
StringWriter sw = new StringWriter();
154+
PrintWriter pw = new PrintWriter(sw);
155+
t.printStackTrace(pw);
156+
String str = sw.toString();
157+
Util.cleanup(sw);
158+
return str;
159+
}
160+
DataInputStream di = new DataInputStream(inp);
161+
int totalAmount = di.readInt();
162+
String lastClass = "";
163+
for (int x = 0; x < totalAmount; x++) {
164+
String current = di.readUTF();
165+
if (current.indexOf('.') > -1) {
166+
lastClass = current;
167+
} else {
168+
for (int iter = 0; iter < size; iter++) {
169+
if (s[iter] == x + 1) {
170+
stk[iter] = lastClass + "." + current;
185171
}
186-
return b.toString();
187-
} catch (IOException ex) {
188-
ex.printStackTrace();
172+
}
189173
}
190-
return "Failed in stack generation for " + t;
174+
}
175+
for (int iter = size - 1; iter >= 0; iter--) {
176+
b.append("at ");
177+
b.append(stk[iter]);
178+
b.append("\n");
179+
}
180+
return b.toString();
181+
} catch (IOException ex) {
182+
ex.printStackTrace();
191183
}
192-
193-
public static void handleException(Throwable err) {
194-
Thread t = Thread.currentThread();
195-
if(t instanceof CodenameOneThread) {
196-
Log.p(err.toString());
197-
Log.p(((CodenameOneThread)t).getStack(err));
198-
//Preferences.set("$CN1Uncaught", true);
199-
CrashReport r = Display.getInstance().getCrashReporter();
200-
if(r != null) {
201-
r.exception(err);
202-
}
203-
}
184+
return "Failed in stack generation for " + t;
185+
}
186+
187+
public static void handleException(Throwable err) {
188+
Thread t = Thread.currentThread();
189+
if (t instanceof CodenameOneThread) {
190+
Log.p(err.toString());
191+
Log.p(((CodenameOneThread) t).getStack(err));
192+
// Preferences.set("$CN1Uncaught", true);
193+
CrashReport r = Display.getInstance().getCrashReporter();
194+
if (r != null) {
195+
r.exception(err);
196+
}
204197
}
198+
}
205199
}

0 commit comments

Comments
 (0)