From 70d0c4a5f2efe9a45a71167204a31bb9536c37aa Mon Sep 17 00:00:00 2001 From: "kh5325.kim" Date: Thu, 24 Oct 2013 17:07:13 +0900 Subject: Upload tizen_2.2 source Change-Id: I3421347c73da03100bb0e5a76ce649fa581634b0 --- .../src/org/tizen/common/builder/BuildProcess.java | 2 +- .../common/connection/ui/SyncProgressMonitor.java | 20 +++- .../src/org/tizen/sdblib/SdbHelper.java | 84 +++++++++------ .../org/tizen/sdblib/SmartDevelopmentBridge.java | 113 ++++++++++----------- .../tizen/sdblib/service/FileEntryInputStream.java | 35 +++++++ .../test/src/org/tizen/sdblib/SdbHelperTest.java | 74 +++++++++++++- org.tizen.common.sign/META-INF/MANIFEST.MF | 3 +- .../sign/preferences/SigningPreferencePage.java | 77 +++++++++++++- .../sign/preferences/SigningProfileContainer.java | 9 +- .../common/sign/preferences/UIMessages.properties | 1 + .../common/sign/signer/SignatureGenerator.java | 14 ++- .../src/org/tizen/common/ITizenNativeXMLStore.java | 83 +++++++++++++++ .../org/tizen/common/file/StandardFileHandler.java | 5 +- .../org/tizen/common/ui/dialog/LocaleDialog.java | 2 +- .../src/org/tizen/common/util/ValidationUtil.java | 27 ++++- .../org/tizen/common/util/ValidationUtilTest.java | 12 +-- package/changelog | 19 ++++ package/pkginfo.manifest | 2 +- 18 files changed, 468 insertions(+), 114 deletions(-) mode change 100644 => 100755 org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java create mode 100644 org.tizen.common/src/org/tizen/common/ITizenNativeXMLStore.java diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java b/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java index eff178cc5..134eb2bdf 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java @@ -206,7 +206,7 @@ public class BuildProcess try { // Step#1 Remove dependency tree about resources what will be built - final Collection projectedResources = new HashSet(); + final Collection projectedResources = new ArrayList(); for ( final Resource resource : sortedResources ) { projectedResources.addAll( removeResource( resource ) ); diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/SyncProgressMonitor.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/SyncProgressMonitor.java index 6896ce2e1..f2f9ded81 100644 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/SyncProgressMonitor.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/SyncProgressMonitor.java @@ -49,6 +49,10 @@ public class SyncProgressMonitor implements ISyncProgressMonitor private String labelTo = "To: "; private String labelSize = "Size: "; + private String lastFromStr = ""; + private String lastToStr = ""; + private String lastSizeStr = ""; + protected long totalWork; protected long worked; @@ -150,12 +154,22 @@ public class SyncProgressMonitor implements ISyncProgressMonitor public void run() { monitor.worked(work); - if(!fromLabel.getText().equals(fromStr)) + + if(!lastFromStr.equals(fromStr)) + { fromLabel.setText(TransferProgressMonitorDialog.shortenText(fromStr, fromLabel)); - if(!toLabel.getText().equals(toStr)) + lastFromStr = fromStr; + } + if(!lastToStr.equals(toStr)) + { toLabel.setText(TransferProgressMonitorDialog.shortenText(toStr, toLabel)); - if(!sizeStr.contains("KB") && !sizeLabel.getText().equals(sizeStr)) + lastToStr = toStr; + } + if(!sizeStr.contains("KB") && !lastSizeStr.equals(sizeStr)) + { sizeLabel.setText(TransferProgressMonitorDialog.shortenText(sizeStr, sizeLabel)); + lastSizeStr = sizeStr; + } } }); } diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java index fa98bd4ed..c2c5f0c14 100755 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java @@ -35,6 +35,9 @@ import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.Charset; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.atomic.AtomicBoolean; import org.tizen.sdblib.exception.SdbCommandRejectedException; import org.tizen.sdblib.exception.TimeoutException; @@ -396,58 +399,75 @@ public class SdbHelper { * @param chan the opened socket to write to. * @param data the buffer to send. * - * @throws TimeoutException in case of timeout on the connection. - * @throws IOException in case of I/O error on the connection. + * @throws IOException if writing is failed */ - public static void write(SocketChannel chan, byte[] data) throws TimeoutException, IOException { + public static + void + write( + final SocketChannel chan, + final byte[] data + ) + throws IOException + { write(chan, data, -1, Preferences.getTimeOut()); } /** * write {@code data} untim time out * - * @param chan the opened socket to write to. - * @param data the buffer to send. - * @param length the length to write or -1 to send the whole buffer. - * @param timeout The timeout value. A timeout of zero means "wait forever". + * @param chan {@link SocketChannel} to write. + * @param data data in byte[]. + * @param length the length to write. + * @param timeout timeout to wait. * - * @throws TimeoutException in case of timeout on the connection. - * @throws IOException in case of I/O error on the connection. + * @throws IOException if writing is failed */ - public static void write( + public static + void + write( final SocketChannel chan, final byte[] data, final int length, final int timeout ) - throws TimeoutException, IOException + throws IOException { - ByteBuffer buf = ByteBuffer.wrap(data, 0, length < 0 ? data.length : length ); - int numWaits = 0; - - while (buf.position() != buf.limit()) { - int count; + final ByteBuffer buf = ByteBuffer.wrap(data, 0, length < 0 ? data.length : length ); + final AtomicBoolean running = new AtomicBoolean( true ); + Timer timer = null; + if ( 0 < timeout ) { + timer = new Timer(); + timer.schedule( new TimerTask() + { + @Override + synchronized public void run() + { + running.set( false ); + } + }, timeout ); + } - count = chan.write(buf); - if (count < 0) { + while (buf.position() != buf.limit() && running.get() ) + { + int count = chan.write( buf ); + if ( count < 0 ) + { Log.d("sdb", "write: channel EOF"); throw new IOException("channel EOF"); - } else if (count == 0) { - // TODO: need more accurate timeout? - if ( 0 < timeout && numWaits * WAIT_TIME > timeout) { - Log.d("sdb", "write: timeout"); - throw new TimeoutException(); - } - // non-blocking spin - try { - Thread.sleep(WAIT_TIME); - } catch (InterruptedException ie) { - } - numWaits++; - } else { - numWaits = 0; } + else if ( 0 == count ) + { + trySleep( WAIT_TIME ); + } + } + if ( buf.position() == buf.limit() ) + { + if(timer != null) + timer.cancel(); + return ; } + Log.d("sdb", "write: Timeout"); + throw new TimeoutException(); } /** diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java old mode 100644 new mode 100755 index 23bb2f375..eb641613b --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SmartDevelopmentBridge.java @@ -141,27 +141,25 @@ SmartDevelopmentBridge } /** - * Creates a new debug bridge from the location of the command line tool. + * Creates {@link SmartDevelopmentBridge} instance. *

- * Any existing server will be disconnected, unless the location is the same and - * forceNewBridge is set to false. - * @param osLocation the location of the command line tool 'sdb' - * @param forceNewBridge force creation of a new bridge even if one with the same location - * already exists. - * @return a connected bridge. + * @param location the location of 'sdb' + * @param bForce force to create new instance + * + * @return {@link SmartDevelopmentBridge} instance */ public static SmartDevelopmentBridge createBridge( - final String osLocation, - final boolean forceNewBridge + final String location, + final boolean bForce ) { init(); synchronized (sLock) { if (instance != null) { - if (instance.mSdbOsLocation != null && instance.mSdbOsLocation.equals(osLocation) && - forceNewBridge == false) { + if (instance.mSdbOsLocation != null && instance.mSdbOsLocation.equals(location) && + bForce == false) { return instance; } else { // stop the current server @@ -169,27 +167,10 @@ SmartDevelopmentBridge } } - instance = new SmartDevelopmentBridge(osLocation); + instance = new SmartDevelopmentBridge(location); instance.start(); - - // because the listeners could remove themselves from the list while processing - // their event callback, we make a copy of the list and iterate on it instead of - // the main list. - // This mostly happens when the application quits. - IDebugBridgeChangeListener[] listenersCopy = sBridgeListeners.toArray( - new IDebugBridgeChangeListener[sBridgeListeners.size()]); - - // notify the listeners of the change - for (IDebugBridgeChangeListener listener : listenersCopy) { - // we attempt to catch any exception so that a bad listener doesn't kill our - // thread - try { - listener.bridgeChanged(instance); - } catch (Exception e) { - Log.e(TAG_SDBLIB, e); - } - } - + + fireBridgetChanged( instance ); return instance; } } @@ -204,6 +185,29 @@ SmartDevelopmentBridge public String getSdbOsLocation() { return mSdbOsLocation; } + + /** + * Fire bridge change event to {@link #sBridgeListeners} + * + */ + protected static + void + fireBridgetChanged( final SmartDevelopmentBridge instance ) + { + for ( final IDebugBridgeChangeListener listener : sBridgeListeners.toArray( new IDebugBridgeChangeListener[0] ) ) + { + try + { + listener.bridgeChanged( instance ); + } + catch ( final Exception e ) + { + Log.e( TAG_SDBLIB, e ); + } + } + + + } /** * disconnect from sdb @@ -214,19 +218,7 @@ SmartDevelopmentBridge instance.stop(); instance = null; - IDebugBridgeChangeListener[] listenersCopy = sBridgeListeners.toArray( - new IDebugBridgeChangeListener[sBridgeListeners.size()]); - - // notify the listeners. - for (IDebugBridgeChangeListener listener : listenersCopy) { - // we attempt to catch any exception so that a bad listener doesn't kill our - // thread - try { - listener.bridgeChanged(instance); - } catch (Exception e) { - Log.e(TAG_SDBLIB, e); - } - } + fireBridgetChanged( null ); } } } @@ -539,10 +531,15 @@ SmartDevelopmentBridge /** * Starts the sdb host side server. + * * @return true if success */ - synchronized boolean startSdb() { - if (mSdbOsLocation == null) { + synchronized + boolean + startSdb() + { + if (mSdbOsLocation == null) + { Log.e(TAG_SDB, "Cannot start sdb when SmartDevelopmentBridge is created without the location of sdb."); //$NON-NLS-1$ return false; @@ -572,10 +569,8 @@ SmartDevelopmentBridge return true; } catch (IOException ioe) { Log.d(TAG_SDBLIB, "unable to run 'sdb': " + ioe.getMessage()); //$NON-NLS-1$ - // we'll return false; } catch (InterruptedException ie) { Log.d(TAG_SDBLIB, "unable to run 'sdb': " + ie.getMessage()); //$NON-NLS-1$ - // we'll return false; } return false; @@ -602,6 +597,13 @@ SmartDevelopmentBridge command[1] = "kill-server"; //$NON-NLS-1$ proc = Runtime.getRuntime().exec(command); status = proc.waitFor(); + + if ( 0 == status ) + { + Log.d(TAG_SDBLIB, "'sdb kill-server' succeeded"); //$NON-NLS-1$ + setStarted(false); + return true; + } } catch (IOException ioe) { // we'll return false; @@ -611,21 +613,16 @@ SmartDevelopmentBridge // we'll return false; } - if (status != 0) { - Log.w(TAG_SDBLIB, - "'sdb kill-server' failed -- run manually if necessary"); //$NON-NLS-1$ - return false; - } + Log.w(TAG_SDBLIB, + "'sdb kill-server' failed -- run manually if necessary"); //$NON-NLS-1$ + return false; - Log.d(TAG_SDBLIB, "'sdb kill-server' succeeded"); //$NON-NLS-1$ - setStarted(false); - return true; } /** - * Get the stderr outputs + * Get and return the stderr outputs * - * @param process The process to get the ouput from + * @param process The process to get the stderr from * * @return contents of error stream( stderr ) * diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java index ae9c2cc4f..f739c1dcd 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryInputStream.java @@ -33,6 +33,7 @@ import static org.tizen.sdblib.SdbHelper.string2bytes; import static org.tizen.sdblib.SdbHelper.write; import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_DATA; import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_DONE; +import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_QUIT; import static org.tizen.sdblib.SmartDevelopmentBridgetConstants.ID_RECV; import static org.tizen.sdblib.service.FileEntryConstants.REMOTE_PATH_MAX_LENGTH; import static org.tizen.sdblib.service.FileEntryConstants.SYNC_DATA_MAX; @@ -55,6 +56,7 @@ import org.tizen.sdblib.SdbResponse; import org.tizen.sdblib.SmartDevelopmentBridge; import org.tizen.sdblib.exception.SyncException; import org.tizen.sdblib.exception.TimeoutException; +import org.tizen.sdblib.util.IOUtil; import org.tizen.sdblib.util.Log; /** @@ -245,5 +247,38 @@ extends InputStream return 0xFF & data[index++]; } + /** + * Create a command with a code and an int values + * @param command + * @param value + * @return + */ + private static + byte[] + createReq( + final byte[] command, + final int value + ) + { + final byte[] array = new byte[8]; + + System.arraycopy(command, 0, array, 0, 4); + toBytes(value, array, 4); + + return array; + } + + + /* (non-Javadoc) + * @see java.io.InputStream#close() + */ + @Override + public void close() throws IOException + { + SdbHelper.write(channel, createReq(ID_QUIT, 0)); + IOUtil.tryClose(channel); + super.close(); + } + } diff --git a/org.tizen.common.sdblib/test/src/org/tizen/sdblib/SdbHelperTest.java b/org.tizen.common.sdblib/test/src/org/tizen/sdblib/SdbHelperTest.java index 0cf5199a7..4db2b4bf5 100755 --- a/org.tizen.common.sdblib/test/src/org/tizen/sdblib/SdbHelperTest.java +++ b/org.tizen.common.sdblib/test/src/org/tizen/sdblib/SdbHelperTest.java @@ -28,12 +28,17 @@ package org.tizen.sdblib; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.when; import static org.tizen.sdblib.SdbHelper.check; import static org.tizen.sdblib.SdbHelper.read; import static org.tizen.sdblib.SdbHelper.readAsString; +import static org.tizen.sdblib.SdbHelper.write; +import static org.tizen.sdblib.util.ThreadUtil.trySleep; +import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; @@ -41,8 +46,10 @@ import org.junit.Test; import org.mockito.Matchers; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import org.tizen.sdblib.exception.TimeoutException; -public class SdbHelperTest +public class +SdbHelperTest { @Test @@ -110,5 +117,70 @@ public class SdbHelperTest assertEquals( "HELO", readAsString( channel, buffer ) ); } + @Test + public + void + test_write() + throws Exception + { + { + final SocketChannel channel = mock( SocketChannel.class ); + final byte[] buffer = "Hello, world".getBytes(); + final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + when( channel.write( any( ByteBuffer.class ) ) ).then( new Answer() + { + + @Override + public Integer answer(InvocationOnMock invocation) throws Throwable + { + final ByteBuffer b = (ByteBuffer) invocation.getArguments()[0]; + int i = 0; + while( i<2 && 0 < b.remaining() ) { + byteOut.write( b.get() ); + ++i; + } + return i; + } + } ); + write( channel, buffer, -1, 1000 ); + + assertArrayEquals( "Hello, world".getBytes(), byteOut.toByteArray() ); + } + + { + final SocketChannel channel = mock( SocketChannel.class ); + final byte[] buffer = "Hello, world".getBytes(); + final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + when( channel.write( any( ByteBuffer.class ) ) ).then( new Answer() + { + + @Override + public + Integer + answer( final InvocationOnMock invocation + ) throws Throwable + { + final ByteBuffer b = (ByteBuffer) invocation.getArguments()[0]; + int i = 0; + while( i<2 && 0 < b.remaining() ) { + byteOut.write( b.get() ); + ++i; + } + trySleep( 300 ); + return i; + } + } ); + try + { + write( channel, buffer, -1, 1000 ); + fail(); + } + catch ( final TimeoutException e ) + { + } + + } + + } } diff --git a/org.tizen.common.sign/META-INF/MANIFEST.MF b/org.tizen.common.sign/META-INF/MANIFEST.MF index f7b3311a5..483634bcc 100644 --- a/org.tizen.common.sign/META-INF/MANIFEST.MF +++ b/org.tizen.common.sign/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.help Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.eclipse.core.resources +Import-Package: org.eclipse.core.resources, + org.eclipse.ui.actions Bundle-Vendor: %Bundle-Vendor Export-Package: hashsign, org.tizen.common.sign, diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/SigningPreferencePage.java b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/SigningPreferencePage.java index a9cbaf817..d0343a969 100755 --- a/org.tizen.common.sign/src/org/tizen/common/sign/preferences/SigningPreferencePage.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/preferences/SigningPreferencePage.java @@ -30,13 +30,21 @@ import static org.tizen.common.util.StringUtil.EMPTY_STRING; import static org.tizen.common.util.StringUtil.isEmpty; import static org.tizen.common.util.StringUtil.trim; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import keycertificategenerator.TizenKeyCertificateGenerator; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -48,6 +56,7 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.JFaceResources; @@ -80,6 +89,7 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.common.TizenHelpContextIds; @@ -92,8 +102,12 @@ import org.tizen.common.sign.ui.CertGenerationDialog.CertDataKey; import org.tizen.common.sign.util.SigningPathUtil; import org.tizen.common.sign.util.SigningProfileUtil; import org.tizen.common.ui.dialog.FileDialogUtils; +import org.tizen.common.util.DialogUtil; import org.tizen.common.util.FileUtil; import org.tizen.common.util.ObjectUtil; +import org.tizen.common.util.ProjectUtil; +import org.tizen.common.util.SWTUtil; +import org.tizen.common.util.StringUtil; public class SigningPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { @@ -108,9 +122,10 @@ public class SigningPreferencePage extends PreferencePage implements IWorkbenchP protected TableViewer distributorTableViewer; protected List