19 September 2012

Terminating a run or test in Scala Build Tool (SBT)

When running a program or test in SBT, if you want to exit from it (and not from SBT) try adding following lines in your build.sbt file:
fork := true

To directly add forking in an SBT session, type
set fork := true

This will not detach and open a new consule from the original sbt console.
But, users can kill this separately.
The way to do this in Max OS or Windows is to search a Java process with command line having sbt-launch in Activity Monitor / Windows Task Manager, and end it.
In Unix, try grepping a process with sbt-launch in a new terminal, and kill it. Command to do that is:
kill -9 `ps -h | grep java | grep -v sbt-launch | grep -v grep | awk '{print $1}'`

By default, the run or test tasks run in the JVM as sbt. Forking can be used to run these tasks in a child process. By default, a forked process uses the same Java and Scala versions being used for the build and the working directory and JVM options of the current process. SBT documentation page discusses how to enable and configure forking for both run and test tasks. Each kind of task may be configured separately by scoping the relevant keys.

17 September 2012

Eclipse crashing and not starting

Problem: After restarting Eclipse, it crashes immediately and asks me to check C:\Users\username\Adobe Flash Builder 4.6\.metadata\.log
In log it shows following error:
!ENTRY org.eclipse.osgi 4 0 2013-02-13 11:53:46.760
!MESSAGE Application error
!STACK 1
org.eclipse.swt.SWTError: Cannot initialize Drop
    at org.eclipse.swt.dnd.DND.error(DND.java:266)
    at org.eclipse.swt.dnd.DND.error(DND.java:227)
    at org.eclipse.swt.dnd.DropTarget.(DropTarget.java:142)
    at org.eclipse.ui.internal.EditorSashContainer.addDropSupport(EditorSashContainer.java:542)
    at org.eclipse.ui.internal.EditorSashContainer.createControl(EditorSashContainer.java:534)
    at org.eclipse.ui.internal.EditorAreaHelper.(EditorAreaHelper.java:41)
    at org.eclipse.ui.internal.WorkbenchPage.init(WorkbenchPage.java:2507)
    at org.eclipse.ui.internal.WorkbenchPage.(WorkbenchPage.java:653)
    at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation.createWorkbenchPage(Workbench3xImplementation.java:47)
    at org.eclipse.ui.internal.WorkbenchWindow$16.runWithException(WorkbenchWindow.java:2222)
    at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
    at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
    at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1595)
    at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at com.adobe.flexbuilder.standalone.FlashBuilderApplication.start(FlashBuilderApplication.java:108)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

!ENTRY org.eclipse.core.jobs 2 2 2013-02-13 11:53:47.166
!MESSAGE Job found still running after platform shutdown.  Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.ui.internal.ide.IDEWorkbenchActivityHelper$4



Solution: Delete C:\Users\username\Adobe Flash Builder 4.6\.metadata\.plugins\org.eclipse.core.resources\.root\.indexes\properties.index file. It was corrupted and throwing EOFException.

12 September 2012

Preserving open nodes in AdvancedDataGrid with HierarchicalCollectionView

My dataProvider is an ArrayCollection, which is populated using XML.

var initXML:XML = <items>
   <item id="News" label="News" value_1="unchecked" value_2="unchecked" value_3="checked"/>
   <item id="BBC" label="The Web" value_1="unchecked" value_2="unchecked" value_3="checked">
       <item id="BBC1" label="BBC Homepage" value_1="unchecked" value_2="unchecked" value_3="checked">
      <item id="YouTube" label="YouTube" value_1="unchecked" value_2="unchecked" value_3="checked"/>
      <item id="GoogleMaps" label="Google Maps" value_1="unchecked" value_2="unchecked" value_3="checked"/>
      <item id="MSN" label="MSN" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       </item>
       <item id="Wikipedia" label="Wikipedia" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="Dilbert" label="Jasper Report" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="PhD" label="Test Page" value_1="unchecked" value_2="unchecked" value_3="unchecked"/>
   </item>
   <item id="Blogs" label="Jasper Reports" value_1="unchecked" value_2="unchecked" value_3="checked">
       <item id="Blog1" label="Report Invoker" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="Blog2" label="Dashboard" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="Blog3" label="Morning Report" value_1="unchecked" value_2="unchecked" value_3="checked"/>
   </item>
    </items>;


public function loadDataResultHandler(newXML:XML):void
{
   dataProvider.removeAll(); // dataProvider is an ArrayCollection
   for each (var s:XML in newXML.item)
      dataProvider.addItem(s);
   dataProvider.refresh();
   advancedDG.validateNow();

   var openNodes:Object;
   if (advancedDG.dataProvider != null)
      openNodes = IHierarchicalCollectionView(advancedDG.dataProvider).openNodes;
   IHierarchicalCollectionView(advancedDG.dataProvider).openNodes = {}; // prevents memory leak

   for each (var openNode:XML in openNodes)
      for each (var item:XML in newXML.descendants("item"))
         if (item.@id[0] == (openNode.@id)[0])
         {
            advancedDG.expandItem(item, true);
            break;
         }
}

10 September 2012

Flash trace log file in Windows 7

In my recent project, I need to look at the Trace output from the Flex application outside Flash Builder.
I have Windows 7 as my operating System.
Following are the steps to setup trace log file:
  1. Download and install Flash player debug version. Check at www.flashplayerversion.com for the version details.
  2. Create a new file named mm.cfg in your home directory. To figure out home directory open a command wondow and type echo %HOMEDRIVE%
        TraceOutputFileEnable=1
        ErrorReportingEnable=1
        MaxWarnings=500
        TraceOutPutFileName=C:\Users\(username)\AppData\Roaming\Macromedia\Flash Player\Logs\flashlog.txt
    
    Last line is optional if you are fine with the output file location.
  3. Open web browser and your Flash application.4. Use a tool like baretail to check the log file.

05 September 2012

Deploying swc library in repository and adding maven artifacts for that

We can either deploy the swc file on a web server or a local Maven repository.
  1. To deploy xyz.swc on a webserver, the command is (in the folder containing xyz.swc):
    mvn deploy:deploy-file -Dfile=xyz.swc -Durl=file:///path/to/repository -DgroupId=com.abc -DartifactId=xyz -Dversion=1.01 -Dpackaging=swc
    
    This deploys the xyz.swc file to /path/to/repository (using the groupId, artifactId, version).
    Users then can refer to this Web URL (by defining a repository in their Maven project) and use xyz as a dependency in their Maven projects.
  2. To deploy the swc in a local Maven repository, we can execute (in the folder containing xyz.swc):
    mvn install:install-file -Dfile=xyz.swc -DgroupId=com.abc -DartifactId=xyz -Dversion=1.01 -Dpackaging=swc -DgeneratePom=true -DcreateChecksum=true
    
    Users then can add the dependency in the pom.xml file under <project> tag as:
        <dependencies>
            <dependency>
                <groupId>com.abc</groupId>
                <artifactId>xyz</artifactId>
                <version>1.01</version>
                <type>swc</type>
            </dependency>
        </dependencies>