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;
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;
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;
import org.tizen.common.ui.dialog.FileDialogUtils;
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 {
protected List<Button> profilesEnableButton;
protected SigningProfileContainer container;
+ protected SigningProfileContainer loadedContainer; // for modified check
-
+ protected final WorkspaceModifyOperation projectCleanOperation = new WorkspaceModifyOperation() {
+ @Override
+ protected void execute(IProgressMonitor monitor)
+ throws CoreException, InvocationTargetException,
+ InterruptedException {
+ monitor = ObjectUtil.nvl( monitor, new NullProgressMonitor() );
+
+ final int totalTick = 100;
+ try {
+ monitor.beginTask( "Clean projects : ", totalTick );
+
+ // interact with an user for updating project signatures
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int cleanTick = totalTick / projects.length;
+
+ boolean bAlways = false;
+ boolean bChoice = true;
+ for ( final IProject project : projects ) {
+ monitor.subTask( project.getName() );
+
+ // check a Tizen project
+ if ( project.isAccessible() && ProjectUtil.isTizenProject( project ) ) {
+ if ( ! bAlways ) {
+ // interact with user
+ int retValue = openQuestionDialogWithAll(
+ getShell(),
+ "Project clean",
+ UIMessages.getString( "org.tizen.common.sign.requiredclean" ) );
+
+ switch ( retValue ) {
+ case 1: // IDialogConstants.YES_TO_ALL_LABEL
+ bAlways = true;
+ case 0: // IDialogConstants.YES_LABEL
+ bChoice = true;
+ break;
+ case 3: // IDialogConstants.NO_TO_ALL_LABEL
+ bAlways = true;
+ case 2: // IDialogConstants.NO_LABEL
+ bChoice = false;
+ break;
+ }
+ }
+
+ if ( bChoice ) {
+ // clean build
+ // TODO: progress sub monitor cannot be used because thread invalid is occurred about CDT build.
+ project.build( IncrementalProjectBuilder.CLEAN_BUILD, null );
+ }
+ }
+
+ monitor.worked( cleanTick );
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+
/**
* Constructor
*/
// load profile
this.container = SigningProfileUtil.getProfileContainerFromFile();
+ this.loadedContainer = SigningProfileUtil.getProfileContainerFromFile();
Composite composite = createComposite(
parent, SWT.NONE, createGridLayout( 1 ), new GridData( GridData.FILL_BOTH ) );
String activeProfileName = SigningProfileUtil.getActiveProfileName();
SigningProfile activeProfile = this.container.getProfileByName( activeProfileName );
this.container.setActiveProfile( activeProfile );
+ this.loadedContainer.setActiveProfile( activeProfile );
this.listViewer.setInput( "profile" );
@Override
public boolean performOk() {
- SigningProfileUtil.setActiveProfileName( container.getActiveProfileName() );
- SigningProfileUtil.writeProfilesToFile( container );
+ // check an active profile change
+ boolean bActiveChanged = false;
+ String newProfileName = container.getActiveProfileName();
+ if ( ! StringUtil.isEmpty( newProfileName ) &&
+ ! newProfileName.equals( loadedContainer.getActiveProfileName() ) ) {
+ bActiveChanged = true;
+ }
+
+ // serialize for compare
+ ByteArrayOutputStream containerOs = new ByteArrayOutputStream();
+ container.writeProfileXML( containerOs );
+ ByteArrayOutputStream loadedContainerOs = new ByteArrayOutputStream();
+ loadedContainer.writeProfileXML( loadedContainerOs );
+
+ // if information was modified
+ boolean bChanged = ! Arrays.equals( containerOs.toByteArray(), loadedContainerOs.toByteArray() );
+ if ( bActiveChanged || bChanged ) {
+ // write profiles
+ SigningProfileUtil.setActiveProfileName( newProfileName );
+ SigningProfileUtil.writeProfilesToFile( container );
+ logger.trace( "Security preferences was saved" );
+
+ // update old comparable info to new info
+ loadedContainer.readProfileXML( new ByteArrayInputStream( containerOs.toByteArray() ) );
+ loadedContainer.setActiveProfile( loadedContainer.getProfileByName( newProfileName ) );
+ try {
+ ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog( getShell() );
+ monitorDialog.run( false, false, projectCleanOperation );
+ } catch (InvocationTargetException e) {
+ logger.error( e.getMessage(), e );
+ return false;
+ } catch (InterruptedException e) {
+ logger.error( e.getMessage(), e );
+ return false;
+ }
+ }
return super.performOk();
}
return null;
}
+ private int openQuestionDialogWithAll(final Shell shell, final String title, final String msg) {
+ final AtomicInteger retValue = new AtomicInteger();
+
+ SWTUtil.syncExec( new Runnable() {
+ @Override
+ public void run() {
+ MessageDialog dialog = new MessageDialog(
+ shell, title, null, msg, MessageDialog.QUESTION,
+ new String[] {
+ IDialogConstants.YES_LABEL,
+ IDialogConstants.YES_TO_ALL_LABEL,
+ IDialogConstants.NO_LABEL,
+ IDialogConstants.NO_TO_ALL_LABEL },
+ 0);
+ dialog.setBlockOnOpen( true );
+ retValue.set( dialog.open() );
+ }
+ });
+
+ return retValue.get();
+ }
+
/**
* TextCellEditor for password processing
*/