summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonyong.lee <bonyong.lee@samsung.com>2013-07-10 15:47:07 +0900
committerBonyong.lee <bonyong.lee@samsung.com>2013-07-10 15:47:07 +0900
commitd7f006fbc10deee482a8bc3d4aa08f6974f5cd92 (patch)
treed79fa2e6a69d930ec1f139beef3fc3b26dfaa1e1
parente3a4b010896a954602b1b930ec8a84f330aa6bc9 (diff)
downloadcommon-eplugin-d7f006fbc10deee482a8bc3d4aa08f6974f5cd92.tar.gz
common-eplugin-d7f006fbc10deee482a8bc3d4aa08f6974f5cd92.tar.bz2
common-eplugin-d7f006fbc10deee482a8bc3d4aa08f6974f5cd92.zip
[Title] Fix arch getting logic
[Desc.] Change arch logic. Before: check "arm" string, in other case guess X86 architecture -> After: check "arm" or "86" string, in other case throw exception. [Issue]
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java26
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java3
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/command/MatcherFactory.java38
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/KeywordBasedMatcher.java1
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java136
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/MultiLineReceiver.java2
-rw-r--r--org.tizen.common.sdblib/test/src/org/tizen/sdblib/command/MultiMatcherTest.java84
7 files changed, 286 insertions, 4 deletions
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
index d9a3d2735..92c0ef8c7 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
@@ -25,6 +25,8 @@
*/
package org.tizen.sdblib;
+import static org.tizen.sdblib.Arch.ARM;
+import static org.tizen.sdblib.Arch.X86;
import static org.tizen.sdblib.DeviceConstants.CMD_ARCHITECTURE_INFO;
import static org.tizen.sdblib.DeviceConstants.CMD_DEVICE_TYPE;
import static org.tizen.sdblib.DeviceConstants.CMD_PKG_TOOL_INSTALL_PATH;
@@ -34,11 +36,14 @@ import static org.tizen.sdblib.DeviceConstants.RESULT_USER_TYPE_ROOT;
import static org.tizen.sdblib.command.Argument.MaxTimeToRespond;
import static org.tizen.sdblib.command.CommandFactory.execute;
import static org.tizen.sdblib.command.MatcherFactory.containsIgnoreCase;
+import static org.tizen.sdblib.command.MatcherFactory.matchers;
import static org.tizen.sdblib.util.Assert.notNull;
import static org.tizen.sdblib.util.StringUtil.isEmpty;
import java.io.IOException;
+import java.nio.channels.AsynchronousCloseException;
+import org.tizen.sdblib.command.Matcher;
import org.tizen.sdblib.command.MatcherFactory;
import org.tizen.sdblib.command.PatternExtractor;
import org.tizen.sdblib.daemon.ServerState;
@@ -491,12 +496,29 @@ implements IDevice
/**
* Initialize basic information
+ * @throws AsynchronousCloseException
*/
public
void
- initialize()
+ initialize() throws AsynchronousCloseException
{
- arch = execute( CMD_ARCHITECTURE_INFO ).in( this, containsIgnoreCase( Arch.ARM.getArch() ) )?Arch.ARM:Arch.X86;
+ final Matcher<?> arm = containsIgnoreCase( ARM.getArch() );
+ final Matcher<?> x86 = containsIgnoreCase( X86.getArch() );
+ Object arch = execute( CMD_ARCHITECTURE_INFO ).in( this, matchers( arm, x86 ) );
+
+ if ( arm.equals( arch ) )
+ {
+ this.arch = ARM;
+ }
+ else if ( arm.equals( arch ) )
+ {
+ this.arch = X86;
+ }
+ else
+ {
+ throw new AsynchronousCloseException();
+ }
+
bEmulator = execute( CMD_DEVICE_TYPE ).in( this, MatcherFactory.equals( RESULT_DEVICE_TYPE_EMULATOR ) );
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java
index ebbb953e8..dcba7aeaa 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/DeviceMonitor.java
@@ -242,12 +242,14 @@ extends AbstractServer
/**
* Updates the device list with the new items received from the monitoring service.
+ * @throws AsynchronousCloseException
*/
protected
void
updateDevices(
final ArrayList<Device> newList
)
+ throws AsynchronousCloseException
{
// because we are going to call mServer.deviceDisconnected which will acquire this lock
// we lock it first, so that the SmartDevelopmentBridge lock is always locked first.
@@ -447,6 +449,7 @@ extends AbstractServer
}
}
} catch (AsynchronousCloseException ace) {
+ Log.e("DeviceMonitor", "sdb closed by the other" );
// this happens because of a call to Quit. We do nothing, and the loop will break.
} catch (TimeoutException ioe) {
handleExpectioninMonitorLoop(ioe);
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/MatcherFactory.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/MatcherFactory.java
index 3d6f5e48b..b75bf9435 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/MatcherFactory.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/MatcherFactory.java
@@ -25,9 +25,13 @@
*/
package org.tizen.sdblib.command;
+import java.util.Arrays;
+import java.util.Collection;
+
import org.tizen.sdblib.command.matcher.Contains;
import org.tizen.sdblib.command.matcher.Equals;
import org.tizen.sdblib.command.matcher.InverseMatcher;
+import org.tizen.sdblib.command.matcher.MultiMatcher;
/**
@@ -131,5 +135,37 @@ MatcherFactory
return new InverseMatcher( receiver );
}
-
+ /**
+ * Return matcher to delegate to multiple matchers
+ *
+ * @param matchers matchers to be delegated
+ *
+ * @return delegate matcher
+ *
+ * @see #matchers(Collection)
+ */
+ public static
+ Matcher<Matcher<?>>
+ matchers(
+ final Matcher<?>... matchers
+ )
+ {
+ return matchers( Arrays.asList( matchers ) );
+ }
+
+ /**
+ * Return matcher to delegate to multiple matchers
+ *
+ * @param matchers matchers to be delegated
+ *
+ * @return delegate matcher
+ */
+ public static
+ Matcher<Matcher<?>>
+ matchers(
+ final Collection<Matcher<?>> matchers
+ )
+ {
+ return new MultiMatcher( matchers );
+ }
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/KeywordBasedMatcher.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/KeywordBasedMatcher.java
index 7bf78ef04..fc0867596 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/KeywordBasedMatcher.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/KeywordBasedMatcher.java
@@ -85,6 +85,7 @@ implements Matcher<Boolean>
*/
@Override
public void processNewLines(String[] lines) {
+
for( final String line : lines )
{
if ( processNewLine( line ) )
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java
new file mode 100644
index 000000000..72809a9cf
--- /dev/null
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/command/matcher/MultiMatcher.java
@@ -0,0 +1,136 @@
+/*
+ * sdblib
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.sdblib.command.matcher;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.tizen.sdblib.command.Matcher;
+import org.tizen.sdblib.receiver.AbstractShellOutputReceiver;
+
+/**
+ * MultiMatcher
+ *
+ * Delegate multi-matchers
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+MultiMatcher
+extends AbstractShellOutputReceiver
+implements Matcher<Matcher<?>>
+{
+ /**
+ * matchers
+ */
+ protected final Collection<Matcher<?>> matchers;
+
+ /**
+ * Constructor with matchers
+ *
+ * @param matchers
+ */
+ @SuppressWarnings("unchecked")
+ public
+ MultiMatcher(
+ final Collection<?> matchers
+ )
+ {
+ this.matchers = (Collection<Matcher<?>>) matchers;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.sdblib.command.Matcher#getResult()
+ */
+ @Override
+ public
+ Matcher<?>
+ getResult()
+ {
+
+ for ( final Matcher<?> matcher : matchers )
+ {
+ final Object obj = matcher.getResult();
+ if ( null == obj )
+ {
+ continue;
+ }
+ return matcher;
+ }
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.tizen.sdblib.receiver.MultiLineReceiver#append(char)
+ */
+ @Override
+ public
+ Appendable
+ append(
+ final char c
+ )
+ throws IOException
+ {
+ for ( final Matcher<?> matcher : matchers )
+ {
+ matcher.append( c );
+ }
+
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.sdblib.receiver.MultiLineReceiver#flush()
+ */
+ @Override
+ public
+ void
+ flush()
+ throws IOException
+ {
+ for ( final Matcher<?> matcher : matchers )
+ {
+ matcher.flush();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.sdblib.receiver.MultiLineReceiver#close()
+ */
+ @Override
+ public
+ void
+ close()
+ throws IOException
+ {
+ for ( final Matcher<?> matcher : matchers )
+ {
+ matcher.close();
+ }
+ }
+
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/MultiLineReceiver.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/MultiLineReceiver.java
index 04198f6e7..2c101f514 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/MultiLineReceiver.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/MultiLineReceiver.java
@@ -191,7 +191,7 @@ implements IShellOutputReceiver
*
* @see com.samsung.sdblib.sdb.IShellOutputReceiver#flush()
*/
- public final void flush()
+ public void flush() throws IOException
{
if ( 0 < lines.size() )
{
diff --git a/org.tizen.common.sdblib/test/src/org/tizen/sdblib/command/MultiMatcherTest.java b/org.tizen.common.sdblib/test/src/org/tizen/sdblib/command/MultiMatcherTest.java
new file mode 100644
index 000000000..49b6dd422
--- /dev/null
+++ b/org.tizen.common.sdblib/test/src/org/tizen/sdblib/command/MultiMatcherTest.java
@@ -0,0 +1,84 @@
+/*
+ * sdblib
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.sdblib.command;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.tizen.sdblib.command.MatcherFactory.containsIgnoreCase;
+
+import org.junit.Test;
+import org.tizen.sdblib.command.matcher.MultiMatcher;
+
+/**
+ * MultiMatcherTest
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+MultiMatcherTest
+{
+
+ /**
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public
+ void
+ test_getResult()
+ throws Exception
+ {
+ {
+ final Matcher<Boolean> arm = containsIgnoreCase( "arm" );
+ final Matcher<Boolean> x86 = containsIgnoreCase( "86" );
+ MultiMatcher target = new MultiMatcher( asList( arm, x86 ) );
+ target.append( "arml7l" );
+ target.close();
+ assertTrue( arm.getResult() );
+ assertFalse( x86.getResult() );
+ }
+
+ {
+ final Matcher<Boolean> arm = containsIgnoreCase( "arm" );
+ final Matcher<Boolean> x86 = containsIgnoreCase( "86" );
+ MultiMatcher target = new MultiMatcher( asList( arm, x86 ) );
+ target.append( "x86" );
+ target.close();
+ assertFalse( arm.getResult() );
+ assertTrue( x86.getResult() );
+ }
+ {
+ final Matcher<Boolean> arm = containsIgnoreCase( "arm" );
+ final Matcher<Boolean> x86 = containsIgnoreCase( "86" );
+ final MultiMatcher target = new MultiMatcher( asList( arm, x86 ) );
+ target.close();
+ assertFalse( arm.getResult() );
+ assertFalse( x86.getResult() );
+ }
+ }
+
+}