[Title] Separated "Build Package" actions and Added "PKG_TYPE"
authordonghee.yang <donghee.yang@samsung.com>
Mon, 26 Mar 2012 15:07:00 +0000 (00:07 +0900)
committerdonghee.yang <donghee.yang@samsung.com>
Mon, 26 Mar 2012 15:07:00 +0000 (00:07 +0900)
org.tizen.nativeplatform/plugin.xml
org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/BuildPackageObjectAction.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/PlatformProjectDependentPackager.java

index 5a927b3..085daa0 100644 (file)
             </action>
         </actionSet>
     </extension>
+    <extension
+          point="org.eclipse.ui.popupMenus">
+
+        <objectContribution
+            adaptable="false"
+            id="org.tizen.nativeplatform.build.BuildPackageObjectContribution"
+            objectClass="org.eclipse.core.resources.IProject">
+            <action
+                  class="org.tizen.nativeplatform.build.BuildPackageObjectAction"
+                  enablesFor="+"
+                  id="org.tizen.nativeplatform.buildPackage.deb"
+                  label="Build Package"
+                  menubarPath="buildGroup">
+            </action>
+            <enablement>
+               <adapt
+                     type="org.eclipse.core.resources.IResource">
+                  <test
+                        property="org.tizen.nativecommon.projectBuildArtefactType"
+                        value="org.tizen.nativeide.buildArtefactType.platform">
+                  </test>
+               </adapt>
+            </enablement>
+        </objectContribution>          
+    </extension>
 <!-- package manager end -->
 </plugin>
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/BuildPackageObjectAction.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/build/BuildPackageObjectAction.java
new file mode 100644 (file)
index 0000000..82edd59
--- /dev/null
@@ -0,0 +1,231 @@
+package org.tizen.nativeplatform.build;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.tizen.nativecommon.build.CheckCancelJob;
+import org.tizen.nativecommon.build.CommonBuildMessages;
+import org.tizen.nativecommon.build.CommonBuildPackageFile;
+import org.tizen.nativecommon.build.CommonProjectDependentPackager;
+import org.tizen.nativecommon.build.ProjectTypeManager;
+import org.tizen.nativecommon.build.SmartBuildInterface;
+import org.tizen.nativecommon.build.exception.SBIException;
+import org.tizen.nativeplatform.Activator;
+
+public class BuildPackageObjectAction implements IWorkbenchWindowActionDelegate, IObjectActionDelegate {
+       protected IProject project;
+       protected IWorkbenchWindow window;
+       private IStatus status = null;
+       private String pkgType;
+
+       public BuildPackageObjectAction() {
+       }
+
+       public BuildPackageObjectAction(IProject project) {
+               this.project = project;
+       }
+
+       @Override
+       public void run(IAction action) {
+               
+               // get pkgType
+               IManagedBuildInfo info = ManagedBuildManager.getBuildInfo( project ) ;
+               IConfiguration defaultConfig = info.getDefaultConfiguration();
+               String targetID = PlatformConfigurationManager.getBuildTargetName( defaultConfig );
+               String toolchainID = SmartBuildInterface.getInstance().getToolchainIDFromTargetID(targetID);
+               if ( toolchainID.contains(".obs") ) { 
+                       pkgType = "RPM";
+               } else {
+                       pkgType = "DEB";
+               }
+               
+               CommonBuildPackageFile.setPackageType(project, pkgType);
+               window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+               ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell());
+
+               try {
+                       dialog.run(true, true, new IRunnableWithProgress() {
+                               @Override
+                               public void run(IProgressMonitor monitor) throws InvocationTargetException,
+                                               InterruptedException {
+                                       status = null;
+                                       monitor.beginTask(CommonBuildMessages.PACKAGING_APPLICATION, -1);
+
+                                       CheckCancelJob cancelJob = new CheckCancelJob(monitor);
+                                       Thread checkCancelThread = new Thread(cancelJob);
+                                       checkCancelThread.start();
+
+                                       CommonProjectDependentPackager packager = ProjectTypeManager.getProjectPackagerInstance(project);
+
+                                       try {
+                                               monitor.subTask("Checking package dependency...");
+                                               packager.buildPackageDependencyCheck();
+                                               // check terminated
+                                               if(cancelJob.getTerminateChecker()){
+                                                       cancelJob.setFinishFlag(true);
+                                                       monitor.done();
+                                                       return ;
+                                               }
+
+                                               checkBuildPackageContinue checkContinueJob = new checkBuildPackageContinue();
+                                               Display.getDefault().syncExec(checkContinueJob);
+                                               while (checkContinueJob.getResult() == -1) {
+                                               }
+                                               if (checkContinueJob.getResult() == 0) {
+                                                       status = new Status(Status.OK, Activator.PLUGIN_ID, CommonBuildMessages.STOP_TO_BUILD_PACKAGE);
+                                                       monitor.done();
+                                                       return;
+                                               } else {
+                                                       monitor.subTask("Building package...");
+                                                       project.build( IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor );
+                                                       packager.buildPackage(pkgType);
+                                               }
+                                       } catch (SBIException e) {
+                                               e.printStackTrace();
+                                               status = new Status(Status.ERROR, Activator.PLUGIN_ID, CommonBuildMessages.FAIL_TO_BUILD_PACKAGE);
+                                               cancelJob.setFinishFlag(true);
+                                               monitor.done();
+                                               return;
+                                       } catch (CoreException e) {
+                                               //e.printStackTrace();
+                                               status = new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage());
+                                               cancelJob.setFinishFlag(true);
+                                               monitor.done();
+                                               return;
+                                       }
+
+                                       // check terminated
+                                       if(cancelJob.getTerminateChecker()){
+                                               cancelJob.setFinishFlag(true);
+                                               monitor.done();
+                                               return ;
+                                       }
+
+                                       monitor.done();
+                               }
+                       });
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+               if (status != null) {
+                       if (status.isOK()) {
+                               MessageDialog.openInformation(window.getShell(), CommonBuildMessages.BUILD_RESULT, status.getMessage());
+                       } else {
+                               MessageDialog.openError(window.getShell(), CommonBuildMessages.BUILD_RESULT, status.getMessage());
+                       }
+               }
+
+
+               // refresh the project explorer
+               try {
+                       project.refreshLocal(IResource.DEPTH_INFINITE, null );
+               } catch (CoreException e) {
+                       e.printStackTrace();
+               }
+       }
+
+       protected File findFirstFilebyExtension(File searchPath, String ext) {
+               File[] allFiles = searchPath.listFiles(new ExtFilter(ext));
+               if (allFiles == null || allFiles.length == 0)
+                       return null;
+               return allFiles[0];
+       }
+
+       protected class ExtFilter implements FilenameFilter {
+               protected String ext;
+
+               public ExtFilter(String ext) {
+                       this.ext = ext;
+               }
+
+               public boolean accept(File dir, String name) {
+                       return name.endsWith(ext);
+               }
+       }
+
+       @Override
+       public void selectionChanged(IAction action, ISelection selection) {
+               Object obj = null;
+
+               if (selection instanceof TreeSelection) {
+                       TreeSelection _selection = (TreeSelection)selection;
+
+                       if (_selection != null) {
+                               obj = _selection.getFirstElement();
+                       }
+               }
+
+               if (obj != null) {
+                       if (obj instanceof IProject) {
+                               project = (IProject) obj;
+                       }
+               }
+       }
+
+       @Override
+       public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+               // do nothing
+       }
+
+       @Override
+       public void dispose() {
+               // do nothing
+       }
+
+       @Override
+       public void init(IWorkbenchWindow window) {
+               // do nothing
+       }
+
+       private class checkBuildPackageContinue implements Runnable {
+               private int result = -1;
+
+               public checkBuildPackageContinue() {
+               }
+
+               @Override
+               public void run() {
+                       synchronized(this) {
+                               // TODO Auto-generated method stub
+                               Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+                               boolean bResult = MessageDialog.openQuestion(shell, "Question",
+                                               "Dependency checking has finished.\nDo you want to continue ?");
+                               if (bResult) {
+                                       result = 1;
+                               } else {
+                                       result = 0;
+                               }
+                       }
+               }
+
+               public int getResult() {
+                       return this.result;
+               }
+       };
+}
+
index cd2bbff..9af74ca 100644 (file)
@@ -61,8 +61,10 @@ public class PlatformProjectDependentPackager extends CommonProjectDependentPack
                String workingDir = getWorkingDir();
 
                String options = String.format(
-                               "-WORKING_DIR=%s",
-                               workingDir );
+                               "-WORKING_DIR=%s" +
+                               " -PKG_TYPE=%s" , 
+                               workingDir ,
+                               pkgType );
 
                return options;
        }
@@ -72,8 +74,10 @@ public class PlatformProjectDependentPackager extends CommonProjectDependentPack
                String workingDir = getWorkingDir(config);
 
                String options = String.format(
-                               "-WORKING_DIR=%s",
-                               workingDir );
+                               "-WORKING_DIR=%s" +
+                               " -PKG_TYPE=%s" , 
+                               workingDir ,
+                               pkgType );
 
                return options;
        }