Skip to content

Commit bd5c009

Browse files
committed
Merge pull request aeron-io#228 from csoroiu/master
A bunch of small changes after gson addition (mostly android)
2 parents 0ae061d + b0963ee commit bd5c009

File tree

14 files changed

+473
-114
lines changed

14 files changed

+473
-114
lines changed

build.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
<property name="dir.main.src" location="main/java"/>
1818
<property name="dir.main.build" location="target/main/java/classes"/>
19-
<property name="dir.main.lib" location="main/lib"/>
2019

2120
<property name="dir.test.src" location="test/java"/>
2221
<property name="dir.test.build" location="target/test/java/classes"/>
@@ -83,12 +82,6 @@
8382
<property name="ossrh.staging.repository.url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2"/>
8483
<property name="ossrh.server.id" value="ossrh"/>
8584

86-
<path id="build.classpath">
87-
<fileset dir="${dir.main.lib}">
88-
<include name="gson.jar"/>
89-
</fileset>
90-
</path>
91-
9285
<path id="test.classpath">
9386
<pathelement path="${dir.main.build}"/>
9487
<pathelement path="${dir.test.build}"/>
@@ -245,7 +238,6 @@
245238

246239
<target name="build" depends="init" description="Build the main source">
247240
<javac srcdir="${dir.main.src}" destdir="${dir.main.build}" includeAntRuntime="false" debug="true">
248-
<classpath refid="build.classpath" />
249241
<compilerarg value="-Xlint:unchecked"/>
250242
<compilerarg value="-XDignore.symbol.file"/>
251243
</javac>
@@ -388,12 +380,17 @@
388380
<attribute name="outputproperty" default=""/>
389381
<attribute name="resultproperty" default=""/>
390382
<attribute name="failonerror" default="true"/>
383+
<attribute name="silent" default="false"/>
391384
<element name="args" implicit="yes" />
392385
<sequential>
386+
<local name="shouldLog"/>
387+
<condition property="shouldLog" value="true">
388+
<isfalse value="@{silent}"/>
389+
</condition>
393390
<echo taskname="adb" message="Running @{command}: @{description}"/>
394391
<exec taskname="adb" executable="${adb.exe}" failonerror="@{failonerror}"
395392
resultproperty="@{resultproperty}">
396-
<redirector outputproperty="@{outputproperty}" alwayslog="true"/>
393+
<redirector outputproperty="@{outputproperty}" alwayslog="${shouldLog}"/>
397394
<arg value="@{command}"/>
398395
<args/>
399396
</exec>
@@ -435,6 +432,7 @@
435432
<dex src="${dir.test.lib}/android/dexmaker-1.1.jar" destfile="${dir.test.android.dexedLibs}/dexmaker-1.1-dexed.jar"/>
436433
<dex src="${dir.test.lib}/android/dexmaker-mockito-1.1.jar" destfile="${dir.test.android.dexedLibs}/dexmaker-mockito-1.1-dexed.jar"/>
437434
<dex src="${dir.test.lib}/objenesis-2.1.jar" destfile="${dir.test.android.dexedLibs}/objenesis-2.1-dexed.jar"/>
435+
<dex src="${dir.test.lib}/gson-2.3.1.jar" destfile="${dir.test.android.dexedLibs}/gson-2.3.1-dexed.jar"/>
438436
<dex src="${dir.test.android.build}" destfile="${dir.test.android.dexedLibs}/sbe-test-dexed.jar"/>
439437
<dex src="${dir.main.android.build}" destfile="${dir.test.android.dexedLibs}/sbe-main-dexed.jar"/>
440438
<dex src="${dir.test.android.dexedLibs}" destfile="${dir.test.android.testpackage}/classes.dex"/>
@@ -488,8 +486,10 @@
488486
<property name="test-results"
489487
value="/data/data/uk.co.real_logic.sbe.android.test/files/test-results.xml"
490488
unless:true="${FILE_ON_EXTERNAL_STORAGE}"/>
491-
<adb command="shell">
492-
<arg line="run-as ${project.app.package} chmod 644 ${test-results}"/>
489+
<!-- ignoring the output, this migth fail on non-rooted devices -->
490+
<!-- but if removed, we won't be able to get the file for rooted devices :) -->
491+
<adb command="shell" description="chmod 644 ${test-results}">
492+
<arg line="run-as ${project.app.package} chmod 644 ${test-results} >/dev/null 2>&amp;1 &amp;&amp; echo true (device might be rooted) || echo failed (device is not rooted)"/>
493493
</adb>
494494
<adb command="pull" description="Pulling the test results from: ${test-results}">
495495
<arg value="${test-results}"/>

examples/java/uk/co/real_logic/sbe/examples/ExampleUsingGeneratedStub.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*/
1616
package uk.co.real_logic.sbe.examples;
1717

18-
import baseline.*;
18+
import baseline.Car;
19+
import baseline.Engine;
20+
import baseline.BooleanType;
21+
import baseline.Model;
22+
import baseline.OptionalExtras;
23+
import baseline.MetaAttribute;
24+
import baseline.MessageHeader;
1925
import uk.co.real_logic.sbe.codec.java.DirectBuffer;
2026

2127
import java.io.FileOutputStream;

main/android/uk/co/real_logic/sbe/codec/java/BitUtil.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import java.security.PrivilegedActionException;
2626
import java.security.PrivilegedExceptionAction;
2727

28-
import android.os.MemoryFile;
29-
3028
/**
3129
* Miscellaneous useful functions for dealing with low level bits and bytes.
3230
*/
@@ -53,8 +51,6 @@ final class BitUtil
5351
private static final MemoryAccess MEMORY_ACCESS;
5452
private static final boolean USE_LONG_ADDRESS;
5553

56-
private static final Field MEMORYFILE_ADDRESS_FIELD;
57-
private static final boolean USE_LONG_MEMORYFILE_ADDRESS;
5854
private static final Constructor<?> DIRECT_BYTE_BUFFER_CONSTRUCTOR;
5955

6056
static
@@ -66,9 +62,6 @@ final class BitUtil
6662
USE_LONG_ADDRESS = EFFECTIVE_DIRECT_ADDRESS_FIELD.getType() == long.class;
6763
MEMORY_ACCESS = USE_LONG_ADDRESS ? new MemoryAccessLongAddress() : new MemoryAccessIntAddress();
6864

69-
MEMORYFILE_ADDRESS_FIELD = getField(MemoryFile.class, "mAddress");
70-
USE_LONG_MEMORYFILE_ADDRESS = MEMORYFILE_ADDRESS_FIELD.getType() == long.class;
71-
7265
final PrivilegedExceptionAction<Constructor<?>> action = new PrivilegedExceptionAction<Constructor<?>>()
7366
{
7467
public Constructor<?> run() throws Exception
@@ -125,29 +118,6 @@ static long getEffectiveDirectAddress(final ByteBuffer buffer)
125118
}
126119
}
127120

128-
/**
129-
* Returns the memory address of a {@link MemoryFile}
130-
*
131-
* @param memoryFile the {@link MemoryFile}
132-
* @return the memory address of the {@link MemoryFile}
133-
*/
134-
static long getMemoryFileAddress(final MemoryFile memoryFile)
135-
{
136-
try
137-
{
138-
return USE_LONG_MEMORYFILE_ADDRESS ? MEMORYFILE_ADDRESS_FIELD
139-
.getLong(memoryFile) : MEMORYFILE_ADDRESS_FIELD.getInt(memoryFile);
140-
}
141-
catch (final IllegalArgumentException ignore)
142-
{
143-
return 0;
144-
}
145-
catch (final IllegalAccessException ignore)
146-
{
147-
return 0;
148-
}
149-
}
150-
151121
/**
152122
* Get the instance of {@link MemoryAccess}.
153123
*

main/android/uk/co/real_logic/sbe/codec/java/DirectBuffer.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.nio.ByteOrder;
2020
import java.util.Locale;
2121

22-
import android.os.MemoryFile;
2322
import libcore.io.Memory;
2423

2524
/**
@@ -37,9 +36,6 @@ public final class DirectBuffer
3736
private int capacity;
3837

3938
private ByteBuffer byteBuffer;
40-
//we keep this reference to avoid being cleaned by GC
41-
@SuppressWarnings("unused")
42-
private MemoryFile memoryFile;
4339

4440
/**
4541
* Attach a view to a byte[] for providing direct access.
@@ -75,16 +71,6 @@ public DirectBuffer(final long address, final int capacity)
7571
wrap(address, capacity);
7672
}
7773

78-
/**
79-
* Attach a view to a {@link MemoryFile} for providing direct access.
80-
*
81-
* @param memoryFile to which the view is attached.
82-
*/
83-
public DirectBuffer(final MemoryFile memoryFile)
84-
{
85-
wrap(memoryFile);
86-
}
87-
8874
/**
8975
* Attach a view to a byte[] for providing direct access.
9076
*
@@ -97,7 +83,6 @@ public void wrap(final byte[] buffer)
9783
capacity = buffer.length;
9884
byteArray = buffer;
9985
byteBuffer = null;
100-
memoryFile = null;
10186
}
10287

10388
/**
@@ -125,7 +110,6 @@ public void wrap(final ByteBuffer buffer)
125110
offset = 0;
126111
effectiveDirectAddress = BitUtil.getEffectiveDirectAddress(buffer);
127112
}
128-
memoryFile = null;
129113
capacity = buffer.capacity();
130114
}
131115

@@ -145,18 +129,6 @@ public void wrap(final long address, final int capacity)
145129
//Memory.memmove needs either a bytebuffer or a bytearray
146130
//it could only work with memory addresses, but it doesn't
147131
byteBuffer = BitUtil.newDirectByteBuffer(effectiveDirectAddress, this.capacity);
148-
memoryFile = null;
149-
}
150-
151-
/**
152-
* Attach a view to a {@link MemoryFile} for providing direct access.
153-
*
154-
* @param memoryFile to which the view is attached.
155-
*/
156-
public void wrap(final MemoryFile memoryFile)
157-
{
158-
wrap(BitUtil.getMemoryFileAddress(memoryFile), memoryFile.length());
159-
this.memoryFile = memoryFile;
160132
}
161133

162134
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2013 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package uk.co.real_logic.sbe.codec.java;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* Group order for repeating groups in encoded messages.
25+
*/
26+
@Retention(RetentionPolicy.RUNTIME)
27+
@Target({ElementType.TYPE})
28+
public @interface GroupOrder
29+
{
30+
Class<?>[] value();
31+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright 2013 Real Logic Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package uk.co.real_logic.sbe.codec.java;
17+
18+
import java.lang.reflect.Method;
19+
import java.lang.reflect.Modifier;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.Collections;
23+
import java.util.HashMap;
24+
import java.util.HashSet;
25+
import java.util.LinkedHashSet;
26+
import java.util.List;
27+
import java.util.Map;
28+
import java.util.Set;
29+
30+
public class MethodSelector
31+
{
32+
private final Set<String> ignoredMethods;
33+
private final Map<Class<?>, Set<String>> sortedMethods = new HashMap<>();
34+
35+
public static Set<String> objectAndIteratorMethods()
36+
{
37+
return new HashSet<>(
38+
Arrays.asList("hashCode", "clone", "toString", "getClass", "next", "hasNext", "remove", "iterator"));
39+
}
40+
41+
public MethodSelector(final Set<String> ignoredMethods)
42+
{
43+
this.ignoredMethods = ignoredMethods;
44+
}
45+
46+
public List<Method> select(final Class<?> clazz)
47+
{
48+
final Method[] methods = clazz.getMethods();
49+
final Set<String> sortedMethodNames = getSortedMethods(clazz, methods);
50+
final Map<String, Method> sortedMethods = new HashMap<>();
51+
final List<Method> unsortedMethods = new ArrayList<>();
52+
53+
for (final Method method : methods)
54+
{
55+
selectMethod(sortedMethodNames, sortedMethods, unsortedMethods, method);
56+
}
57+
58+
for (final String name : sortedMethodNames)
59+
{
60+
unsortedMethods.add(sortedMethods.get(name));
61+
}
62+
63+
return unsortedMethods;
64+
}
65+
66+
private Set<String> getSortedMethods(final Class<?> clazz, final Method[] methods)
67+
{
68+
final Set<String> sortedMethodNames = sortedMethods.get(clazz);
69+
if (sortedMethodNames == null)
70+
{
71+
final GroupOrder order = (GroupOrder)clazz.getAnnotation(GroupOrder.class);
72+
if (order == null)
73+
{
74+
sortedMethods.put(clazz, Collections.<String>emptySet());
75+
76+
return Collections.emptySet();
77+
}
78+
else
79+
{
80+
final Set<String> result = new LinkedHashSet<>();
81+
for (final Class<?> groupClazz : order.value())
82+
{
83+
for (final Method method : methods)
84+
{
85+
if (method.getReturnType() == groupClazz && method.getParameterTypes().length == 0)
86+
{
87+
result.add(method.getName());
88+
}
89+
}
90+
}
91+
sortedMethods.put(clazz, result);
92+
93+
return result;
94+
}
95+
}
96+
97+
return sortedMethodNames;
98+
}
99+
100+
private void selectMethod(
101+
final Set<String> sortedMethodNames,
102+
final Map<String, Method> sortedMethods,
103+
final List<Method> unsortedMethods,
104+
final Method method)
105+
{
106+
final int mods = method.getModifiers();
107+
if (!Modifier.isPublic(mods))
108+
{
109+
return;
110+
}
111+
if (Modifier.isStatic(mods))
112+
{
113+
return;
114+
}
115+
if (method.getParameterTypes().length != 0)
116+
{
117+
return;
118+
}
119+
if (method.getReturnType().equals(Void.TYPE))
120+
{
121+
return;
122+
}
123+
124+
final String name = method.getName();
125+
if (ignoredMethods.contains(name))
126+
{
127+
return;
128+
}
129+
130+
if (sortedMethodNames == null)
131+
{
132+
unsortedMethods.add(method);
133+
}
134+
else
135+
{
136+
if (sortedMethodNames.contains(name))
137+
{
138+
sortedMethods.put(name, method);
139+
}
140+
else
141+
{
142+
unsortedMethods.add(method);
143+
}
144+
}
145+
}
146+
}

main/java/uk/co/real_logic/sbe/codec/java/GroupOrder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
@Target({ElementType.TYPE})
2828
public @interface GroupOrder
2929
{
30-
Class[] value();
30+
Class<?>[] value();
3131
}

0 commit comments

Comments
 (0)