View | Details | Raw Unified | Return to bug 234139 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mtj/internal/core/project/midp/MidletSuiteProject.java (-12 / +19 lines)
Lines 60-65 Link Here
60
import org.eclipse.jdt.core.JavaConventions;
60
import org.eclipse.jdt.core.JavaConventions;
61
import org.eclipse.jdt.core.JavaCore;
61
import org.eclipse.jdt.core.JavaCore;
62
import org.eclipse.jdt.core.JavaModelException;
62
import org.eclipse.jdt.core.JavaModelException;
63
import org.eclipse.mtj.core.IMTJCoreConstants;
63
import org.eclipse.mtj.core.MTJCore;
64
import org.eclipse.mtj.core.MTJCore;
64
import org.eclipse.mtj.core.build.preverifier.IPreverificationError;
65
import org.eclipse.mtj.core.build.preverifier.IPreverificationError;
65
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
66
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
Lines 74-80 Link Here
74
import org.eclipse.mtj.core.project.runtime.MTJRuntimeList;
75
import org.eclipse.mtj.core.project.runtime.MTJRuntimeList;
75
import org.eclipse.mtj.core.sdk.device.IDevice;
76
import org.eclipse.mtj.core.sdk.device.IDevice;
76
import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice;
77
import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice;
77
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
78
import org.eclipse.mtj.internal.core.Messages;
78
import org.eclipse.mtj.internal.core.Messages;
79
import org.eclipse.mtj.internal.core.build.BuildSpecManipulator;
79
import org.eclipse.mtj.internal.core.build.BuildSpecManipulator;
80
import org.eclipse.mtj.internal.core.build.BuildStateMachine;
80
import org.eclipse.mtj.internal.core.build.BuildStateMachine;
Lines 97-102 Link Here
97
 * </p>
97
 * </p>
98
 * 
98
 * 
99
 * @author Craig Setera
99
 * @author Craig Setera
100
 *         Gustavo de Paula (Motorola)  - Add proguard preverifier options
101
 *         David Aragão (Motorola) - Add proguard preverifier refactoring
100
 * @noextend This class is not intended to be subclassed by clients.
102
 * @noextend This class is not intended to be subclassed by clients.
101
 */
103
 */
102
public final class MidletSuiteProject implements IMidletSuiteProject {
104
public final class MidletSuiteProject implements IMidletSuiteProject {
Lines 123-132 Link Here
123
	 */
125
	 */
124
	public static String getDefaultJadFileName(IProject project) {
126
	public static String getDefaultJadFileName(IProject project) {
125
		String projectName = project.getName();
127
		String projectName = project.getName();
126
		return NLS.bind(IMTJCoreConstants.VERSION_NLS_BIND_TEMPLATE,
128
		return NLS.bind("{0}.{1}", new String[] {
127
				new String[] { projectName.replace(' ', '_'),
129
				projectName.replace(' ', '_'), APP_DESCRIPTOR_FILE_EXT }); //$NON-NLS-1$
128
						APP_DESCRIPTOR_FILE_EXT }); //$NON-NLS-1$
129
130
	}
130
	}
131
131
132
	// The java project on which this MIDlet suite is based
132
	// The java project on which this MIDlet suite is based
Lines 164-170 Link Here
164
		initializeMetadata();
164
		initializeMetadata();
165
165
166
		MTJRuntime mtjRuntime = getRuntimeList().getActiveMTJRuntime();
166
		MTJRuntime mtjRuntime = getRuntimeList().getActiveMTJRuntime();
167
		if ((mtjRuntime != null) && (mtjRuntime.getDevice() == null)) {
167
		       if (mtjRuntime != null && mtjRuntime.getDevice() == null) {
168
			try {
168
			try {
169
				if (getProject().findMarkers(
169
				if (getProject().findMarkers(
170
						IMTJCoreConstants.JAVAME_MISSING_DEVICE_MARKER, false,
170
						IMTJCoreConstants.JAVAME_MISSING_DEVICE_MARKER, false,
Lines 205-213 Link Here
205
	 * org.eclipse.mtj.core.project.IMTJProject#createPackage(org.eclipse.core
205
	 * org.eclipse.mtj.core.project.IMTJProject#createPackage(org.eclipse.core
206
	 * .runtime.IProgressMonitor, boolean, boolean)
206
	 * .runtime.IProgressMonitor, boolean, boolean)
207
	 */
207
	 */
208
	public void createPackage(boolean obfuscate,
208
	public void createPackage(IProgressMonitor monitor, boolean obfuscate,
209
			boolean packageInactiveConfigs, IProgressMonitor monitor)
209
			boolean packageInactiveConfigs) throws CoreException {
210
			throws CoreException {
211
210
212
		Map<String, String> args = new HashMap<String, String>();
211
		Map<String, String> args = new HashMap<String, String>();
213
		args.put(PackageBuilder.ARG_DO_PACKAGE, Boolean.TRUE.toString());
212
		args.put(PackageBuilder.ARG_DO_PACKAGE, Boolean.TRUE.toString());
Lines 224-230 Link Here
224
		BuildSpecManipulator manipulator = new BuildSpecManipulator(this
223
		BuildSpecManipulator manipulator = new BuildSpecManipulator(this
225
				.getProject());
224
				.getProject());
226
		// Set builder arguments
225
		// Set builder arguments
227
		manipulator.setBuilderArguments(IMTJCoreConstants.PACKAGE_BUILDER_ID,
226
		manipulator.setBuilderArguments(org.eclipse.mtj.internal.core.IMTJCoreConstants.PACKAGE_BUILDER_ID,
228
				args);
227
				args);
229
		manipulator.commitChanges(monitor);
228
		manipulator.commitChanges(monitor);
230
229
Lines 235-241 Link Here
235
		}
234
		}
236
235
237
		// Reset builder Arguments
236
		// Reset builder Arguments
238
		manipulator.setBuilderArguments(IMTJCoreConstants.PACKAGE_BUILDER_ID,
237
		manipulator.setBuilderArguments(org.eclipse.mtj.internal.core.IMTJCoreConstants.PACKAGE_BUILDER_ID,
239
				new HashMap<String, String>());
238
				new HashMap<String, String>());
240
		manipulator.commitChanges(monitor);
239
		manipulator.commitChanges(monitor);
241
240
Lines 794-800 Link Here
794
				stateMachine.start(monitor);
793
				stateMachine.start(monitor);
795
794
796
				getProject().build(IncrementalProjectBuilder.FULL_BUILD,
795
				getProject().build(IncrementalProjectBuilder.FULL_BUILD,
797
						IMTJCoreConstants.PACKAGE_BUILDER_ID, args, monitor);
796
						org.eclipse.mtj.internal.core.IMTJCoreConstants.PACKAGE_BUILDER_ID, args, monitor);
798
			}
797
			}
799
		}
798
		}
800
		// restore project settings after packaging configs
799
		// restore project settings after packaging configs
Lines 905-908 Link Here
905
		}
904
		}
906
	}
905
	}
907
906
907
	@Override
908
	public void createPackage(boolean obfuscate,
909
			boolean packageInactiveConfigs, IProgressMonitor monitor)
910
			throws CoreException {
911
		// TODO Auto-generated method stub
912
		
913
	}
914
908
}
915
}
(-)src/org/eclipse/mtj/internal/core/IMTJCoreConstants.java (-1 / +4 lines)
Lines 76-82 Link Here
76
    public static final String PREF_PREVERIFY_CONFIG_LOCATION = "preverify_config_location"; //$NON-NLS-1$
76
    public static final String PREF_PREVERIFY_CONFIG_LOCATION = "preverify_config_location"; //$NON-NLS-1$
77
    public static final String PREF_PREVERIFY_CONFIG_VALUE = "preverify_config_value"; //$NON-NLS-1$
77
    public static final String PREF_PREVERIFY_CONFIG_VALUE = "preverify_config_value"; //$NON-NLS-1$
78
    public static final String PREF_DEFAULT_PREVERIFIER = "default_preverifier"; //$NON-NLS-1$
78
    public static final String PREF_DEFAULT_PREVERIFIER = "default_preverifier"; //$NON-NLS-1$
79
79
    public static final String PREF_PREVERIFY_TYPE = "preverify_type"; //$NON-NLS-1$
80
    public static final String PREF_PREVERIFY_TYPE_EMULATOR = "preverify_emulator"; //$NON-NLS-1$
81
    public static final String PREF_PREVERIFY_TYPE_PROGUARD = "preverify_proguard"; //$NON-NLS-1$
82
    
80
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_JAD = "jad"; //$NON-NLS-1$
83
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_JAD = "jad"; //$NON-NLS-1$
81
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM = "platform"; //$NON-NLS-1$
84
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM = "platform"; //$NON-NLS-1$
82
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED = "specified"; //$NON-NLS-1$
85
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED = "specified"; //$NON-NLS-1$
(-)src/org/eclipse/mtj/internal/core/PreferenceAccessor.java (+15 lines)
Lines 44-49 Link Here
44
 * A helper wrapper around the more complex preferences supported by MTJ.
44
 * A helper wrapper around the more complex preferences supported by MTJ.
45
 * 
45
 * 
46
 * @author Craig Setera
46
 * @author Craig Setera
47
 *
48
 *         Gustavo de Paula (Motorola) - Add proguard preverifier
47
 */
49
 */
48
public class PreferenceAccessor {
50
public class PreferenceAccessor {
49
51
Lines 354-357 Link Here
354
356
355
        return prefNode;
357
        return prefNode;
356
    }
358
    }
359
    
360
    /**
361
     * 
362
     * @param project
363
     * @return
364
     */
365
    public String getPreverifierType (IProject project) {
366
        IEclipsePreferences preferences = getProjectPreferences(project,
367
                IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT,
368
                IMTJCoreConstants.PREF_PREVERIFY_TYPE);
369
        return preferences.get(IMTJCoreConstants.PREF_PREVERIFY_TYPE, 
370
        		MTJCorePreferenceInitializer.PREF_DEF_PREVERIFY_TYPE);
371
    }
357
}
372
}
(-)src/org/eclipse/mtj/internal/core/MTJCorePreferenceInitializer.java (-4 / +7 lines)
Lines 55-61 Link Here
55
    public static final String PREF_DEF_PREVERIFY_CONFIG_LOCATION = PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM;
55
    public static final String PREF_DEF_PREVERIFY_CONFIG_LOCATION = PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM;
56
    public static final String PREF_DEF_PREVERIFY_CONFIG_VALUE = ""; //$NON-NLS-1$
56
    public static final String PREF_DEF_PREVERIFY_CONFIG_VALUE = ""; //$NON-NLS-1$
57
    public static final String PREF_DEF_DEFAULT_PREVERIFIER = ""; //$NON-NLS-1$
57
    public static final String PREF_DEF_DEFAULT_PREVERIFIER = ""; //$NON-NLS-1$
58
58
    //public static final boolean PREF_DEF_PREVERIFY_BUILT_IN = false;
59
    public static final String PREF_DEF_PREVERIFY_TYPE = IMTJCoreConstants.PREF_PREVERIFY_TYPE_EMULATOR;
60
    
59
    public static final String PREF_DEF_WTK_ROOT = ""; //$NON-NLS-1$
61
    public static final String PREF_DEF_WTK_ROOT = ""; //$NON-NLS-1$
60
    public static final String PREF_DEF_ANTENNA_JAR = ""; //$NON-NLS-1$
62
    public static final String PREF_DEF_ANTENNA_JAR = ""; //$NON-NLS-1$
61
63
Lines 103-111 Link Here
103
                PREF_DEF_PREVERIFY_CONFIG_LOCATION);
105
                PREF_DEF_PREVERIFY_CONFIG_LOCATION);
104
        prefs.setDefault(PREF_PREVERIFY_CONFIG_VALUE,
106
        prefs.setDefault(PREF_PREVERIFY_CONFIG_VALUE,
105
                PREF_DEF_PREVERIFY_CONFIG_VALUE);
107
                PREF_DEF_PREVERIFY_CONFIG_VALUE);
106
        prefs
108
        prefs.setDefault(PREF_PREVERIFY_CONFIG_VALUE,
107
                .setDefault(PREF_DEFAULT_PREVERIFIER,
109
        		PREF_DEF_PREVERIFY_TYPE);
108
                        PREF_DEF_DEFAULT_PREVERIFIER);
110
        prefs.setDefault(PREF_DEFAULT_PREVERIFIER,
111
                PREF_DEF_DEFAULT_PREVERIFIER);
109
112
110
        prefs.setDefault(PREF_ANTENNA_JAR, PREF_DEF_ANTENNA_JAR);
113
        prefs.setDefault(PREF_ANTENNA_JAR, PREF_DEF_ANTENNA_JAR);
111
        prefs.setDefault(PREF_WTK_ROOT, PREF_DEF_WTK_ROOT);
114
        prefs.setDefault(PREF_WTK_ROOT, PREF_DEF_WTK_ROOT);
(-)src/org/eclipse/mtj/core/build/preverifier/ProguardPreverifier.java (+563 lines)
Line 0 Link Here
1
/**
2
 * Copyright (c) 2003,2008 Motorola Inc. and others.
3
 * All Rights Reserved.
4
 * Licensed under the Eclipse Public License - v 1.0
5
 * For more information see http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors:
8
 *     Gustavo de Paula (Motorola)  - Initial Creation 	         
9
 */
10
package org.eclipse.mtj.core.build.preverifier;
11
12
import java.io.File;
13
import java.io.FileFilter;
14
import java.io.IOException;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.regex.Matcher;
20
import java.util.regex.Pattern;
21
22
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Status;
28
import org.eclipse.debug.core.IStreamListener;
29
import org.eclipse.debug.core.model.IProcess;
30
import org.eclipse.debug.core.model.IStreamMonitor;
31
import org.eclipse.debug.core.model.IStreamsProxy;
32
import org.eclipse.jdt.core.IJavaProject;
33
import org.eclipse.jdt.core.JavaModelException;
34
import org.eclipse.jdt.launching.IVMInstall;
35
import org.eclipse.jdt.launching.JavaRuntime;
36
import org.eclipse.mtj.core.MTJCore;
37
import org.eclipse.mtj.core.persistence.IPersistenceProvider;
38
import org.eclipse.mtj.core.persistence.PersistenceException;
39
import org.eclipse.mtj.core.project.IMTJProject;
40
import org.eclipse.mtj.core.project.midp.IMidletSuiteProject;
41
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
42
import org.eclipse.mtj.internal.core.build.BuildConsoleProxy;
43
import org.eclipse.mtj.internal.core.build.BuildLoggingConfiguration;
44
import org.eclipse.mtj.internal.core.build.IBuildConsoleProxy;
45
import org.eclipse.mtj.internal.core.build.preverifier.IClassErrorInformation;
46
import org.eclipse.mtj.internal.core.build.preverifier.PreverificationError;
47
import org.eclipse.mtj.internal.core.build.preverifier.PreverificationErrorLocation;
48
import org.eclipse.mtj.internal.core.build.preverifier.PreverificationErrorLocationType;
49
import org.eclipse.mtj.internal.core.build.preverifier.PreverificationErrorType;
50
import org.eclipse.mtj.internal.core.util.TemporaryFileManager;
51
import org.eclipse.mtj.internal.core.util.Utils;
52
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
53
54
55
/**
56
 * Use proguard to preverify the MIDlet suite classes. Design and code is mostly 
57
 * based on org.eclipse.mtj.core.model.impl.StandardPreverifier.
58
 * 
59
 * TODO Refactore code to have a common class to be used both by StandPreverifier and ProguardPreverifier
60
 * 
61
 * @author wgp010
62
 */
63
public class ProguardPreverifier implements IPreverifier {
64
65
    /**
66
     * The list of locations in which to look for the java executable in
67
     * candidate VM install locations, relative to the VM install location.
68
     * Code from org.eclipse.mtj.core.model.implJavaEmulatorDevice. 
69
     * TODO Refactore to have a common place for it
70
     */
71
    private static final String[] CANDIDATE_JAVA_LOCATIONS = {
72
            "bin" + File.separatorChar + "java", //$NON-NLS-2$ //$NON-NLS-1$
73
            "bin" + File.separatorChar + "java.exe", //$NON-NLS-2$ //$NON-NLS-1$
74
            "jre" + File.separatorChar + "bin" + File.separatorChar + "java", //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
75
            "jre"   + File.separatorChar + "bin" + File.separatorChar + "java.exe" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
76
    
77
	/**
78
	 * Path to proguard lib
79
	 */
80
	private String proguardJarFilePath = null;
81
82
	/**
83
	 * Max number of characters in the command
84
	 */
85
    private static final int MAX_COMMAND_LENGTH = 2000;
86
87
    
88
    // The regular expression we will use to match the preverify
89
    // error
90
    private static final String PREV_ERR_REGEX = "^Unable to access jarfile (\\S*)$";
91
92
    // The compiled pattern for regular expression matching
93
    private static final Pattern PREV_ERR_PATTERN = Pattern.compile(
94
            PREV_ERR_REGEX, Pattern.MULTILINE);
95
96
    /**
97
     * Class constructor
98
     */
99
    public ProguardPreverifier () {
100
    	this.proguardJarFilePath = MTJCore.getProguardJarFile().getAbsolutePath();
101
    }
102
    
103
	@Override
104
	public PreverificationError[] preverify(IMTJProject mtjProject,
105
			IResource[] toVerify, IFolder outputFolder, IProgressMonitor monitor)
106
			throws CoreException {
107
        ArrayList allErrors = new ArrayList();
108
109
        // Create the temporary file of commands for
110
        // the verifier
111
        ensureFolderExists(outputFolder, monitor);
112
       
113
        // construct the command line to call proguard
114
        ArrayList baseArguments = constructCommandLine();
115
        
116
        // read the final arguments that will be added to proguard command line. those parameters should be added
117
        // after the -injar parameter
118
        File outputFile = outputFolder.getLocation().toFile();
119
        String[] configurationParameters = getProguardFinalConfigurationParameters(mtjProject, outputFile.getAbsolutePath());
120
121
        ArrayList arguments = new ArrayList(baseArguments);
122
        
123
        //add the output folder 
124
        addOutputToInJar (arguments, mtjProject);
125
        
126
        for (int i = 0; i < toVerify.length; i++) {
127
            IResource resource = toVerify[i];
128
            
129
            //add projects and jar files 
130
            switch (resource.getType()) {
131
            case IResource.FOLDER:
132
            case IResource.PROJECT:
133
            	addFileToInJar(arguments, resource.getLocation().toOSString());
134
                break;
135
136
            case IResource.FILE:
137
            	if (resource.getName().endsWith(".jar")) {
138
            		addFileToInJar(arguments, resource.getLocation().toOSString());
139
                }
140
                break;
141
            }
142
143
            if (commandLength(arguments) > MAX_COMMAND_LENGTH) {
144
                // Configuration parameters
145
                for (String configuration:configurationParameters) {
146
                	arguments.add(configuration);
147
                }
148
            	
149
                // Launch the system process
150
                String[] commandLine = (String[]) arguments
151
                        .toArray(new String[arguments.size()]);
152
                PreverificationError[] errors = runPreverifier(commandLine,
153
                        null, monitor);
154
                allErrors.addAll(Arrays.asList(errors));
155
156
                arguments = new ArrayList(baseArguments);
157
                //add the output folder 
158
                addOutputToInJar (arguments, mtjProject);
159
            }
160
        }
161
162
        if (arguments.size() != baseArguments.size()) {
163
            for (String configuration:configurationParameters) {
164
            	arguments.add(configuration);
165
            }
166
        	
167
            // Launch the system process
168
            String[] commandLine = (String[]) arguments
169
                    .toArray(new String[arguments.size()]);
170
            PreverificationError[] errors = runPreverifier(commandLine, null,
171
                    monitor);
172
            allErrors.addAll(Arrays.asList(errors));
173
        }
174
175
        return (PreverificationError[]) allErrors
176
                .toArray(new PreverificationError[allErrors.size()]);
177
	}
178
179
	@Override
180
	public PreverificationError[] preverifyJarFile(
181
			IMTJProject mtjProject, File jarFile,
182
			IFolder outputFolder, IProgressMonitor monitor)
183
			throws CoreException{
184
        // Rather than trying to preverify a jar file, we will expand it
185
        // first and then preverify against the expanded classes.
186
        File srcDirectory = new File("");
187
		try {
188
			srcDirectory = TemporaryFileManager.instance.createTempDirectory(
189
			        jarFile.getName().replace('.', '_') + "_", ".tmp");
190
		} catch (IOException ioe) {
191
			IStatus status = new Status(IStatus.ERROR,
192
                    IMTJCoreConstants.PLUGIN_ID, "Failed to create directory.",
193
                    ioe);
194
            throw new CoreException(status);
195
		}
196
        srcDirectory.mkdirs();
197
        
198
        try {
199
			Utils.extractArchive(jarFile, srcDirectory);
200
        } catch (SecurityException se) {
201
            IStatus status = new Status(IStatus.ERROR,
202
                    IMTJCoreConstants.PLUGIN_ID,
203
                    "Failed to inflate jar file due to a security violation.",
204
                    se);
205
            throw new CoreException(status);
206
        } catch (IOException ioe) {
207
            IStatus status = new Status(IStatus.ERROR,
208
                    IMTJCoreConstants.PLUGIN_ID, "Failed to inflate jar file.",
209
                    ioe);
210
            throw new CoreException(status);
211
        }
212
213
        // Create the target directory for the preverification. We will
214
        // tell the preverifier to use this when doing the preverification.
215
        File tgtDirectory = new File("");
216
		try {
217
			tgtDirectory = TemporaryFileManager.instance.createTempDirectory(
218
			        jarFile.getName().replace('.', '_') + "_", ".tmp");
219
		} catch (IOException ioe) {
220
			IStatus status = new Status(IStatus.ERROR,
221
                    IMTJCoreConstants.PLUGIN_ID, "Failed to create directory.",
222
                    ioe);
223
            throw new CoreException(status);
224
		}
225
        tgtDirectory.mkdirs();
226
227
        ArrayList arguments = constructCommandLine();
228
        arguments.add(srcDirectory.toString());
229
230
        // Launch the system process
231
        String[] commandLine = (String[]) arguments
232
                .toArray(new String[arguments.size()]);
233
        PreverificationError[] errors = runPreverifier(commandLine,
234
                null, monitor);
235
236
        // TODO we need to test the outcome of the previous before going much
237
        // further
238
        // here...
239
        // Copy all of the non-class resources so they end up back in the
240
        // jar file
241
        FileFilter classFilter = new FileFilter() {
242
            public boolean accept(File pathname) {
243
                return pathname.isDirectory()
244
                        || !pathname.getName().endsWith(".class");
245
            }
246
        };
247
        try {
248
			Utils.copy(srcDirectory, tgtDirectory, classFilter);
249
		} catch (SecurityException se) {
250
			IStatus status = new Status(IStatus.ERROR,
251
                    IMTJCoreConstants.PLUGIN_ID,
252
                    "Failed copy specified source due to a security violation.",
253
                    se);
254
            throw new CoreException(status);
255
		} catch (IOException ioe) {
256
			IStatus status = new Status(IStatus.ERROR,
257
                    IMTJCoreConstants.PLUGIN_ID, "Failed to copy specified source.",
258
                    ioe);
259
            throw new CoreException(status);
260
		}
261
262
        // Finally, re-jar the output of the pre-verification into the requested
263
        // jar file...
264
        File outputJarFile = new File(outputFolder.getLocation().toFile(),
265
                jarFile.getName());
266
        try {
267
			Utils.createArchive(outputJarFile, tgtDirectory);
268
		} catch (IOException ioe) {
269
			IStatus status = new Status(IStatus.ERROR,
270
                    IMTJCoreConstants.PLUGIN_ID, "Failed to create zip source folder.",
271
                    ioe);
272
            throw new CoreException(status);
273
		}
274
275
        return errors;
276
	}
277
278
	public void loadUsing(IPersistenceProvider persistenceProvider)
279
			throws PersistenceException {
280
		// Not necessary to load any data
281
	}
282
283
	public void storeUsing(IPersistenceProvider persistenceProvider)
284
			throws PersistenceException {
285
		// Not necessary to store any data
286
	}
287
288
    /**
289
     * Run the preverifier program and capture the errors that occurred during
290
     * pre-verification.
291
     * 
292
     * @param commandLine
293
     * @param environment
294
     * @throws CoreException
295
     */
296
    private PreverificationError[] runPreverifier(String[] commandLine,
297
            String[] environment, IProgressMonitor monitor)
298
            throws CoreException {
299
        final ArrayList errorList = new ArrayList();
300
301
        IProcess process = Utils.launchApplication(commandLine, null,
302
                environment, "Preverifier", "CLDC Preverifier");
303
304
        // Listen on the process output streams
305
        IStreamsProxy proxy = process.getStreamsProxy();
306
        if (BuildLoggingConfiguration.getInstance().isPreverifierOutputEnabled()) {
307
            BuildConsoleProxy.getInstance()
308
                    .traceln("======================== Launching Preverification =========================");
309
            BuildConsoleProxy.getInstance().addConsoleStreamListener(
310
                    IBuildConsoleProxy.Stream.ERROR, proxy
311
                            .getErrorStreamMonitor());
312
            BuildConsoleProxy.getInstance().addConsoleStreamListener(
313
                    IBuildConsoleProxy.Stream.OUTPUT, proxy
314
                            .getOutputStreamMonitor());
315
        }
316
317
        proxy.getErrorStreamMonitor().addListener(new IStreamListener() {
318
            public void streamAppended(String text, IStreamMonitor monitor) {
319
                handleErrorReceived(text, errorList);
320
            }
321
        });
322
323
        // Wait until completion
324
        while ((!monitor.isCanceled()) && (!process.isTerminated())) {
325
            try {
326
                Thread.sleep(100);
327
            } catch (InterruptedException e) {
328
            }
329
            ;
330
        }
331
332
        if (BuildLoggingConfiguration.getInstance().isPreverifierOutputEnabled()) {
333
            BuildConsoleProxy.getInstance()
334
                    .traceln("======================== Preverification exited with code: "
335
                            + process.getExitValue());
336
        }
337
338
        return (PreverificationError[]) errorList
339
                .toArray(new PreverificationError[errorList.size()]);
340
    }
341
342
    /**
343
     * Handle the arrival of text on the error stream.
344
     * 
345
     * TODO Change to support proguard error messages
346
     *  
347
     * @param text
348
     * @param errorList
349
     */
350
    private void handleErrorReceived(String text, List errorList) {
351
        text = text.trim();
352
        Matcher matcher = PREV_ERR_PATTERN.matcher(text);
353
        if (matcher.find()) {
354
            // Found a match for the error...
355
            if (matcher.groupCount() > 0) {
356
                final String classname = matcher.group(1);
357
358
                String errorText = "Error preverifying class";
359
                if (matcher.end() < text.length()) {
360
                    StringBuffer sb = new StringBuffer(errorText);
361
                    sb.append(": ");
362
363
                    String detail = text.substring(matcher.end());
364
                    detail = detail.trim();
365
                    sb.append(detail);
366
                    errorText = sb.toString();
367
                }
368
369
                IClassErrorInformation classInfo = new IClassErrorInformation() {
370
                    public String getName() {
371
                        return classname;
372
                    }
373
374
                    public String getSourceFile() {
375
                        return null;
376
                    }
377
                };
378
379
                PreverificationErrorLocation location = new PreverificationErrorLocation(
380
                        PreverificationErrorLocationType.UNKNOWN_LOCATION,
381
                        classInfo);
382
                PreverificationError error = new PreverificationError(
383
                        PreverificationErrorType.UNKNOWN_ERROR, location, text);
384
                errorList.add(error);
385
            }
386
        } else {
387
            MTJLogger.log(IStatus.WARNING, text);
388
        }
389
    }
390
    /**
391
     * Ensure the specified output folder exists or create if it does not
392
     * already exist.
393
     * 
394
     * @param folder
395
     * @param monitor
396
     * @throws CoreException
397
     */
398
    private void ensureFolderExists(IFolder folder, IProgressMonitor monitor)
399
            throws CoreException {
400
        // Make sure the output folder exists before we start
401
        if (!folder.exists()) {
402
            folder.create(true, true, monitor);
403
        }
404
    }
405
    
406
    /**
407
     * Construct the command line for the specified pre-verification.
408
     * 
409
     * @param midletProject
410
     * @param target
411
     * @return
412
     * @throws CoreException
413
     */
414
    private ArrayList constructCommandLine() throws CoreException {
415
        ArrayList arguments = new ArrayList();
416
417
        // The program we are running...
418
        arguments.add(this.getJavaExecutable().getAbsolutePath());
419
        arguments.add("-jar");
420
        arguments.add(this.proguardJarFilePath);
421
422
        return arguments;
423
    }
424
    
425
    /**
426
     * Return the parameters to be used for controlling the proguard preverifier
427
     * 
428
     * @param midletProject
429
     * @return
430
     * @throws CoreException if an error occurs working with the MIDlet project.
431
     */
432
    private String [] getProguardFinalConfigurationParameters(IMTJProject mtjProject, String output) throws CoreException {
433
        return new String [] {
434
        		"-outjars",
435
        		"'"+output+"'",
436
        		"-libraryjars",
437
        		this.getFullClasspath(mtjProject),
438
        		"'-ignorewarnings'",
439
        		"-dontusemixedcaseclassnames",
440
        		"-dontshrink",
441
        		"-dontoptimize",
442
        		"-dontobfuscate",
443
        		"-microedition"
444
        };
445
    }
446
    
447
    /**
448
     * Get the full classpath including all J2ME libraries.
449
     * 
450
     * @param midletProject
451
     * @return
452
     * @throws CoreException
453
     */
454
    private String getFullClasspath(IMTJProject mtjProject)
455
            throws CoreException {
456
        IJavaProject javaProject = mtjProject.getJavaProject();
457
        
458
        String[] entries = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
459
460
        // start in 1 to remove the output folder from the runtime. the output folder should be included in the
461
        // -injar proguard options
462
        StringBuffer sb = new StringBuffer();
463
        for (int i = 1; i < entries.length; i++) {
464
            if (i != 1) {
465
                sb.append(File.pathSeparatorChar);
466
            }
467
            sb.append("'"+entries[i]+"'");
468
        }
469
470
        return sb.toString();
471
    }
472
473
    /**
474
     * Add the output folder target to be verified.
475
     * 
476
     * @param args
477
     * @param resource
478
     * @throws JavaModelException
479
     */
480
    private void addOutputToInJar(List args, IMTJProject mtjProject)
481
            throws JavaModelException {
482
    	
483
        // Find the source directory this class resides in
484
    	String outputPath = null;
485
    	
486
    	String s1 = mtjProject.getProject().getLocation().toOSString();
487
    	String s2 = mtjProject.getJavaProject().getOutputLocation().removeFirstSegments(1).toOSString();
488
    	//IPath.SEPARATOR
489
    	outputPath = s1 + File.separatorChar + s2;
490
    	
491
    	if (outputPath != null) {
492
    		args.add("-injars");
493
            args.add("'"+outputPath+"'");
494
        }
495
    }
496
497
    /**
498
     * Add any file to be preverified
499
     * 
500
     * @param args
501
     * @param resource
502
     * @throws JavaModelException
503
     */
504
    private void addFileToInJar(List args, String filePath)
505
            throws JavaModelException {
506
    	if (filePath != null) {
507
    		args.add("-injars");
508
            args.add("'"+filePath+"'");
509
        }
510
    }
511
    
512
    
513
    /**
514
     * Return the length of the command-line length given the specified argument
515
     * list.
516
     * 
517
     * @param arguments
518
     * @return
519
     */
520
    private int commandLength(ArrayList arguments) {
521
        int length = 0;
522
523
        Iterator iter = arguments.iterator();
524
        while (iter.hasNext()) {
525
            Object arg = (Object) iter.next();
526
            length += arg.toString().length();
527
            if (iter.hasNext())
528
                length++;
529
        }
530
531
        return length;
532
    }
533
    
534
    /**
535
     * Return the Java executable to be used for launching this device.
536
     * Code from org.eclipse.mtj.core.model.implJavaEmulatorDevice. 
537
     * TODO Refactore to have a common place for it
538
     * 
539
     * @return
540
     */
541
    private File getJavaExecutable() {
542
        File executable = null;
543
544
        IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
545
        File installLocation = vmInstall.getInstallLocation();
546
547
        for (int i = 0; i < CANDIDATE_JAVA_LOCATIONS.length; i++) {
548
            String javaLocation = CANDIDATE_JAVA_LOCATIONS[i];
549
            File javaExecutable = new File(installLocation, javaLocation);
550
            if (javaExecutable.exists()) {
551
                executable = javaExecutable;
552
                break;
553
            }
554
        }
555
        return executable;
556
    }
557
558
	@Override
559
	public File getPreverifierExecutable() {
560
		// TODO Auto-generated method stub
561
		return null;
562
	}
563
}
(-)src/org/eclipse/mtj/core/IMTJCoreConstants.java (+207 lines)
Line 0 Link Here
1
/**
2
 * Copyright (c) 2003,2009 Craig Setera and others.
3
 * 
4
 * All Rights Reserved.
5
 * Licensed under the Eclipse Public License - v 1.0
6
 * For more information see http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Craig Setera (EclipseME) - Initial implementation
10
 *     Diego Sandin (Motorola)  - Refactoring package and class name 
11
 *                                to follow eclipse standards
12
 *     Hugo Raniere (Motorola)  - Removing Preprocessor code
13
 *     Feng Wang (Sybase)       - Add LAUNCH_FROM_JAD_FOLDER constant for
14
 *                                launching from JAD.
15
 *     Hugo Raniere (Motorola)  - Adding key to represent default preverifier
16
 *     Diego Sandin (Motorola)  - Re-enabling Preprocessor code
17
 *     Hugo Raniere (Motorola)  - Adding key to represent a java me problem marker
18
 *     Diego Sandin (Motorola)  - Adding key to represent a missing device definition
19
 *                                problem marker
20
 *     Gang Ma      (Sybase)    - Adding key to represent preprocess debug level
21
 *     David Marques(Motorola)  - Adding key to represent process type.
22
 *     David Marques(Motorola)  - Adding L10N Nature Constant.
23
 *     Gustavo de Paula (Motorola)  - Add types of preverifiers
24
 *     
25
 */
26
package org.eclipse.mtj.core;
27
28
/**
29
 * Constant definitions for use throughout the plug-in.
30
 * <p>
31
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
32
 * of a work in progress. There is no guarantee that this API will work or that
33
 * it will remain the same. Please do not use this API without consulting with
34
 * the MTJ team.
35
 * </p>
36
 * 
37
 * @since 1.0
38
 * @noimplement This interface is not intended to be implemented by clients.
39
 */
40
public interface IMTJCoreConstants {
41
42
    // The plug-in ID
43
    public static final String PLUGIN_ID = "org.eclipse.mtj.core"; //$NON-NLS-1$
44
45
    // Directory preference keys and defaults
46
    public static final String PREF_DEPLOYMENT_DIR = "deployment_dir"; //$NON-NLS-1$
47
    public static final String PREF_VERIFIED_DIR = "verified_dir"; //$NON-NLS-1$
48
49
    // New project creation preferences
50
    public static final String PREF_USE_RESOURCES_DIR = "use_resources_dir"; //$NON-NLS-1$
51
    public static final String PREF_RESOURCES_DIR = "resources_dir"; //$NON-NLS-1$
52
    public static final String PREF_FORCE_JAVA11 = "force_java11"; //$NON-NLS-1$
53
54
    // Over the Air preferences
55
    public static final String PREF_OTA_SERVER_START_AT_START = "ota_start_at_start"; //$NON-NLS-1$
56
    public static final String PREF_OTA_PORT_DEFINED = "ota_port_defined"; //$NON-NLS-1$
57
    public static final String PREF_OTA_PORT = "ota_port"; //$NON-NLS-1$
58
    public static final String PREF_OTA_AUTODEPLOY = "ota_autodeploy"; //$NON-NLS-1$
59
60
    // Proguard obfuscation preferences
61
    public static final String PREF_OBFUSCATION_USE_PROJECT = "obfuscate_use_project"; //$NON-NLS-1$
62
    public static final String PREF_PROGUARD_DIR = "proguard_dir"; //$NON-NLS-1$
63
    public static final String PREF_PROGUARD_USE_SPECIFIED = "proguard_use_specified"; //$NON-NLS-1$
64
    public static final String PREF_PROGUARD_OPTIONS = "proguard_options"; //$NON-NLS-1$
65
    public static final String PREF_PROGUARD_KEEP = "proguard_keep"; //$NON-NLS-1$
66
67
    // Packaging related preferences
68
    public static final String PREF_PKG_USE_PROJECT = "pkg_use_project"; //$NON-NLS-1$
69
    public static final String PREF_PKG_AUTOVERSION = "pkg_autoversion"; //$NON-NLS-1$
70
    public static final String PREF_PKG_EXCLUDED_PROPS = "pkg_excluded_props"; //$NON-NLS-1$
71
    public static final String PREF_PKG_BUILD_XML = "pkg_build_xml"; //$NON-NLS-1$
72
73
    // Preverifier related preferences
74
    public static final String PREF_PREVERIFY_USE_PROJECT = "pkg_use_project"; //$NON-NLS-1$
75
76
    public static final String PREF_PREVERIFY_CONFIG_LOCATION = "preverify_config_location"; //$NON-NLS-1$
77
    public static final String PREF_PREVERIFY_CONFIG_VALUE = "preverify_config_value"; //$NON-NLS-1$
78
    public static final String PREF_DEFAULT_PREVERIFIER = "default_preverifier"; //$NON-NLS-1$
79
    public static final String PREF_PREVERIFY_TYPE = "preverify_type";
80
    public static final String PREF_PREVERIFY_TYPE_EMULATOR = "preverify_emulator";
81
    public static final String PREF_PREVERIFY_TYPE_DEFAULT = "preverify_default";
82
    public static final String PREF_PREVERIFY_TYPE_PROGUARD = "preverify_proguard";
83
84
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_JAD = "jad"; //$NON-NLS-1$
85
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM = "platform"; //$NON-NLS-1$
86
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED = "specified"; //$NON-NLS-1$
87
88
    public static final String MANIFEST_FILE_NAME = "META-INF/MANIFEST.MF";
89
90
    // Antenna settings
91
    public static final String PREF_WTK_ROOT = "wtk_root"; //$NON-NLS-1$
92
    public static final String PREF_ANTENNA_JAR = "antenna_jar"; //$NON-NLS-1$
93
94
    // Miscellaneous preferences
95
    public static final String PREF_RMTDBG_TIMEOUT = "rmt_debug_delay"; //$NON-NLS-1$
96
    public static final String PREF_RMTDBG_INTERVAL = "rmt_debug_poll_interval"; //$NON-NLS-1$
97
    public static final String PREF_AUTO_LAUNCH_MIGRATION = "auto_launch_migration"; //$NON-NLS-1$
98
99
    // Preprocessor preferences
100
    public static final String PREF_PREPROCESS_USE_PROJECT = "preprocess_use_project"; //$NON-NLS-1$
101
    public static final String PREF_PREPROCESS_DEBUG_LEVEL = "preprocess_debuglevel"; //$NON-NLS-1$
102
103
    /**
104
     * Debugging property keys Key that uses "true" or "false" to control
105
     * whether or not to dump the launch command line for the emulator
106
     */
107
    public static final String PROP_DUMP_LAUNCH = "mtj.dump.launch"; //$NON-NLS-1$
108
109
    /** The superclass of all MIDlets */
110
    public static final String MIDLET_SUPERCLASS = "javax.microedition.midlet.MIDlet"; //$NON-NLS-1$
111
112
    // Project folder names...
113
114
    /**
115
     * The directory used to hold temporary files such as preverified and
116
     * incrementally built jar files
117
     */
118
    public static final String TEMP_FOLDER_NAME = ".mtj.tmp"; //$NON-NLS-1$
119
120
    /**
121
     * The sub-folder of the TEMP folder that holds runtime classes
122
     */
123
    public static final String RUNTIME_FOLDER_NAME = "runtime";
124
125
    // The sub-folder of the TEMP folder that holds verified classes and
126
    // libraries
127
    public static final String VERIFIED_FOLDER_NAME = "verified"; //$NON-NLS-1$
128
129
    // The sub-folder of the TEMP folder that holds the JAR and JAD files for
130
    // execution by the emulator
131
    public static final String EMULATION_FOLDER_NAME = "emulation"; //$NON-NLS-1$
132
133
    // The sub-folder of the ".mtj.tmp" folder that holds JAR and JAD for
134
    // launching from JAD emulation
135
    public static final String LAUNCH_FROM_JAD_FOLDER = "launchFromJAD"; //$NON-NLS-1$
136
137
    // Miscellaneous
138
    public static final String PROGUARD_JAR = "proguard.jar"; //$NON-NLS-1$
139
140
    public static final String MTJ_NATURE_ID = PLUGIN_ID + ".nature"; //$NON-NLS-1$
141
    public static final String J2ME_PREPROCESSED_NATURE_ID = PLUGIN_ID
142
            + ".preprocessedNature"; //$NON-NLS-1$
143
144
    public static final String J2ME_PREPROCESSING_NATURE_ID = PLUGIN_ID
145
            + ".preprocessingNature"; //$NON-NLS-1$
146
    public static final String J2ME_PREVERIFIER_ID = PLUGIN_ID + ".preverifier"; //$NON-NLS-1$
147
    public static final String J2ME_PREPROCESSOR_ID = PLUGIN_ID
148
            + ".preprocessor"; //$NON-NLS-1$
149
    public static final String JAVAME_PROBLEM_MARKER = PLUGIN_ID + ".problem"; //$NON-NLS-1$
150
151
    /**
152
     * Missing device definition resource marker ID
153
     */
154
    public static final String JAVAME_MISSING_DEVICE_MARKER = PLUGIN_ID
155
            + ".device.missing"; //$NON-NLS-1$
156
157
    public static final String J2ME_PREPROCESSED_CONTAINER = PLUGIN_ID
158
            + ".PP_CONTAINER"; //$NON-NLS-1$
159
    public static final String J2ME_TOOLKIT_TYPES_ID = "wirelessToolkitTypes"; //$NON-NLS-1$
160
    public static final String J2ME_CONFIGURATIONS_ID = "configurations"; //$NON-NLS-1$
161
    public static final String J2ME_PROFILES_ID = "profiles"; //$NON-NLS-1$
162
163
    public static final String MTJ_PROCESS_TYPE = "MTJProcess"; //$NON-NLS-1$
164
165
    // ////////////////////////////////////////////////////////////////////
166
    // Error messages
167
    // ////////////////////////////////////////////////////////////////////
168
    /** No MIDlets defined during OTA launch */
169
    public static final int ERR_OTA_NO_MIDLETS = 100;
170
171
    /** Errors occurred during obfuscation */
172
    public static final int ERR_OBFUSCATION_ERRORS = 101;
173
174
    /** Error searching for jar executable */
175
    public static final int ERR_COULD_NOT_FIND_JAR_TOOL = 102;
176
177
    /** Need signature passwords (not really an error, but triggers a dialog) */
178
    public static final int INFO_NEED_SIGNATURE_PASSWORDS = 103;
179
180
    /**
181
     * Need check for debug setting(not really an error, but triggers a dialog
182
     * if the current debugger setting is not satisfied to debug a MIDlet)
183
     */
184
    public static final int INFO_DEBUGGER_SETTINGS_CHECK = 104;
185
186
    /**
187
     * This constant is the old eclipse me nature id.
188
     */
189
    public static final String ECLIPSE_ME_NATURE = "eclipseme.core.nature"; //$NON-NLS-1$
190
191
    /**
192
     * This constant holds the L10N Nature ID
193
     */
194
    public static final String L10N_NATURE_ID = PLUGIN_ID + ".l10nNature"; //$NON-NLS-1$
195
196
    /**
197
     * This constant holds the L10N Builder ID
198
     */
199
    public static final String L10N_BUILDER_ID = PLUGIN_ID + ".l10nBuilder"; //$NON-NLS-1$
200
201
    /**
202
     * This constant holds the JMUnit Nature ID
203
     */
204
    public static final String JMUNIT_NATURE_ID = "org.eclipse.mtj.jmunit.jmunitNature"; //$NON-NLS-1$
205
206
    public static final String VERSION_NLS_BIND_TEMPLATE = "{0}.{1}";
207
}
(-)src/org/eclipse/mtj/internal/ui/preferences/PreverificationPreferencePage.java (-365 / +484 lines)
Lines 16-21 Link Here
16
 *     				  correcting "Restore Defaults" behavior
16
 *     				  correcting "Restore Defaults" behavior
17
 *     Diego Sandin (Motorola)  - Use Eclipse Message Bundles [Bug 255874]
17
 *     Diego Sandin (Motorola)  - Use Eclipse Message Bundles [Bug 255874]
18
 *     Gustavo de Paula (Motorola)  - Preverifier api refactoring
18
 *     Gustavo de Paula (Motorola)  - Preverifier api refactoring
19
 *     Gustavo de Paula (Motorola) - Change preverification to add proguard support
20
 *     David Aragao (Motorola) - Preverification type availability
19
 */
21
 */
20
package org.eclipse.mtj.internal.ui.preferences;
22
package org.eclipse.mtj.internal.ui.preferences;
21
23
Lines 33-42 Link Here
33
import org.eclipse.core.runtime.Platform;
34
import org.eclipse.core.runtime.Platform;
34
import org.eclipse.core.runtime.SubProgressMonitor;
35
import org.eclipse.core.runtime.SubProgressMonitor;
35
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
36
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
37
import org.eclipse.jdt.core.IJavaProject;
36
import org.eclipse.jface.operation.IRunnableWithProgress;
38
import org.eclipse.jface.operation.IRunnableWithProgress;
39
import org.eclipse.jface.preference.FieldEditorPreferencePage;
37
import org.eclipse.jface.preference.FileFieldEditor;
40
import org.eclipse.jface.preference.FileFieldEditor;
38
import org.eclipse.jface.preference.IPreferenceStore;
41
import org.eclipse.jface.preference.IPreferenceStore;
39
import org.eclipse.jface.preference.PreferencePage;
42
import org.eclipse.jface.preference.RadioGroupFieldEditor;
43
import org.eclipse.jface.util.IPropertyChangeListener;
44
import org.eclipse.jface.util.PropertyChangeEvent;
40
import org.eclipse.mtj.core.MTJCore;
45
import org.eclipse.mtj.core.MTJCore;
41
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
46
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
42
import org.eclipse.mtj.core.sdk.device.IAPI;
47
import org.eclipse.mtj.core.sdk.device.IAPI;
Lines 41-46 Link Here
41
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
46
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
42
import org.eclipse.mtj.core.sdk.device.IAPI;
47
import org.eclipse.mtj.core.sdk.device.IAPI;
43
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
48
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
49
import org.eclipse.mtj.internal.core.PreferenceAccessor;
44
import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration;
50
import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration;
45
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
51
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
46
import org.eclipse.mtj.internal.ui.IEmbeddableWorkbenchPreferencePage;
52
import org.eclipse.mtj.internal.ui.IEmbeddableWorkbenchPreferencePage;
Lines 64-479 Link Here
64
 * 
70
 * 
65
 * @author Craig Setera
71
 * @author Craig Setera
66
 */
72
 */
67
public class PreverificationPreferencePage extends PreferencePage implements
73
public class PreverificationPreferencePage extends FieldEditorPreferencePage
68
        IEmbeddableWorkbenchPreferencePage {
74
		implements IEmbeddableWorkbenchPreferencePage {
75
76
	private static final String[] BUTTON_TEXTS = new String[] {
77
			MTJUIMessages.PreverificationPreferencePage_use_jad_settings_label_text,
78
			MTJUIMessages.PreverificationPreferencePage_use_project_settings_label_text,
79
			MTJUIMessages.PreverificationPreferencePage_use_specific_config_label_text, };
80
81
	private static final String[] CONFIG_FILE_LOCATIONS = new String[] {
82
			IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_JAD,
83
			IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM,
84
			IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED, };
85
86
	private Combo configCombo;
87
	private IAPI[] configSpecs;
88
	private FileFieldEditor defaultPreverifierField;
89
	private Group defaultPreverifierGroup;
90
	private boolean embeddedInProperties;
69
91
70
    private static final String[] BUTTON_TEXTS = new String[] {
92
	// The java project on which this MIDlet suite is based
71
            MTJUIMessages.PreverificationPreferencePage_use_jad_settings_label_text,
93
	private IJavaProject javaProject;
72
            MTJUIMessages.PreverificationPreferencePage_use_project_settings_label_text,
73
            MTJUIMessages.PreverificationPreferencePage_use_specific_config_label_text, };
74
94
75
    private static final String[] CONFIG_FILE_LOCATIONS = new String[] {
95
	private Button[] preverificationRadios;
76
            IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_JAD,
77
            IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM,
78
            IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED, };
79
96
80
    private Combo configCombo;
97
	private RadioGroupFieldEditor radioGroupFieldEditor;
81
    private IAPI[] configSpecs;
82
    private FileFieldEditor defaultPreverifierField;
83
    private boolean embeddedInProperties;
84
98
85
    private Button[] preverificationRadios;
99
	/**
100
	 * Default constructor.
101
	 */
102
	public PreverificationPreferencePage() {
103
		this(false, MTJUIPlugin.getDefault().getCorePreferenceStore());
104
	}
86
105
87
    /**
106
	/**
88
     * Default constructor.
107
	 * Constructor for use when embedding the preference page within a
89
     */
108
	 * properties page.
90
    public PreverificationPreferencePage() {
109
	 * 
91
        this(false, MTJUIPlugin.getDefault().getCorePreferenceStore());
110
	 * @param embeddedInProperties
92
    }
111
	 * @param preferenceStore
112
	 *            a table mapping named preferences to values
113
	 */
114
	public PreverificationPreferencePage(boolean embeddedInProperties,
115
			IPreferenceStore preferenceStore) {
93
116
94
    /**
117
		this.embeddedInProperties = embeddedInProperties;
95
     * Constructor for use when embedding the preference page within a
118
		setPreferenceStore(preferenceStore);
96
     * properties page.
119
		configSpecs = Configuration.values();
97
     * 
120
	}
98
     * @param embeddedInProperties
99
     * @param preferenceStore a table mapping named preferences to values
100
     */
101
    public PreverificationPreferencePage(boolean embeddedInProperties,
102
            IPreferenceStore preferenceStore) {
103
121
104
        this.embeddedInProperties = embeddedInProperties;
122
	/**
105
        setPreferenceStore(preferenceStore);
123
	 * Launch the build of the MIDlet suites.
106
        configSpecs = Configuration.values();
124
	 * 
107
    }
125
	 * @param toBuild
126
	 */
127
	public void doBuild(final IProject[] toBuild) {
128
		// The work to be done.
129
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
130
			public void run(IProgressMonitor monitor)
131
					throws InvocationTargetException {
132
				try {
133
					for (int i = 0; i < toBuild.length; i++) {
134
						SubProgressMonitor subMonitor = new SubProgressMonitor(
135
								monitor, IProgressMonitor.UNKNOWN);
136
						toBuild[i].build(IncrementalProjectBuilder.FULL_BUILD,
137
								subMonitor);
138
						subMonitor.done();
139
					}
140
				} catch (CoreException e) {
141
					throw new InvocationTargetException(e);
142
				}
143
			}
144
		};
145
		try {
146
			PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
147
					runnable);
148
		} catch (InterruptedException e) {
149
		} catch (InvocationTargetException e) {
150
			MTJLogger
151
					.log(
152
							IStatus.WARNING,
153
							MTJUIMessages.PreverificationPreferencePage_error_build_suite,
154
							e.getCause());
155
		}
156
	}
108
157
109
    /**
158
	/*
110
     * Launch the build of the MIDlet suites.
159
	 * (non-Javadoc)
111
     * 
160
	 * 
112
     * @param toBuild
161
	 * @see
113
     */
162
	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
114
    public void doBuild(final IProject[] toBuild) {
163
	 */
115
        // The work to be done.
164
	public void init(IWorkbench workbench) {
116
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
165
	}
117
            public void run(IProgressMonitor monitor)
118
                    throws InvocationTargetException {
119
                try {
120
                    for (int i = 0; i < toBuild.length; i++) {
121
                        SubProgressMonitor subMonitor = new SubProgressMonitor(
122
                                monitor, IProgressMonitor.UNKNOWN);
123
                        toBuild[i].build(IncrementalProjectBuilder.FULL_BUILD,
124
                                subMonitor);
125
                        subMonitor.done();
126
                    }
127
                } catch (CoreException e) {
128
                    throw new InvocationTargetException(e);
129
                }
130
            }
131
        };
132
        try {
133
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
134
                    runnable);
135
        } catch (InterruptedException e) {
136
        } catch (InvocationTargetException e) {
137
            MTJLogger
138
                    .log(
139
                            IStatus.WARNING,
140
                            MTJUIMessages.PreverificationPreferencePage_error_build_suite,
141
                            e.getCause());
142
        }
143
    }
144
166
145
    /* (non-Javadoc)
167
	/*
146
     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
168
	 * (non-Javadoc)
147
     */
169
	 * 
148
    public void init(IWorkbench workbench) {
170
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
149
    }
171
	 */
172
	@Override
173
	public void performApply() {
174
		super.performApply();
175
	}
150
176
151
    /* (non-Javadoc)
177
	/*
152
     * @see org.eclipse.jface.preference.PreferencePage#performApply()
178
	 * (non-Javadoc)
153
     */
179
	 * 
154
    @Override
180
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
155
    public void performApply() {
181
	 */
156
        super.performApply();
182
	@Override
157
    }
183
	public void performDefaults() {
184
		setControlsFromDefaults();
185
		super.performDefaults();
186
	}
158
187
159
    /* (non-Javadoc)
188
	/*
160
     * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
189
	 * (non-Javadoc)
161
     */
190
	 * 
162
    @Override
191
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
163
    public void performDefaults() {
192
	 */
164
        setControlsFromDefaults();
193
	@Override
165
        super.performDefaults();
194
	public boolean performOk() {
166
    }
195
		setPreferencesFromControls();
196
		if (!embeddedInProperties) {
197
			buildSuites();
198
		}
167
199
168
    /* (non-Javadoc)
200
		return super.performOk();
169
     * @see org.eclipse.jface.preference.PreferencePage#performOk()
201
	}
170
     */
171
    @Override
172
    public boolean performOk() {
173
        setPreferencesFromControls();
174
        if (!embeddedInProperties) {
175
            buildSuites();
176
        }
177
202
178
        return super.performOk();
203
	/**
179
    }
204
	 * Add the controls for choosing the preverification configuration.
205
	 * 
206
	 * @param composite
207
	 */
208
	private void addConfigurationControls(Composite composite) {
209
		Group preverifyConfigGroup = new Group(composite, SWT.NONE);
210
		preverifyConfigGroup
211
				.setText(MTJUIMessages.PreverificationPreferencePage_preverifyConfigGroup_label_text);
212
		preverifyConfigGroup.setLayout(new GridLayout(1, false));
213
		preverifyConfigGroup.setLayoutData(new GridData(
214
				GridData.FILL_HORIZONTAL));
180
215
181
    /**
216
		preverificationRadios = new Button[BUTTON_TEXTS.length];
182
     * Add the controls for choosing the preverification configuration.
217
		for (int i = 0; i < BUTTON_TEXTS.length; i++) {
183
     * 
218
			preverificationRadios[i] = new Button(preverifyConfigGroup,
184
     * @param composite
219
					SWT.RADIO);
185
     */
220
			preverificationRadios[i].setText(BUTTON_TEXTS[i]);
186
    private void addConfigurationControls(Composite composite) {
187
        Group preverifyConfigGroup = new Group(composite, SWT.NONE);
188
        preverifyConfigGroup
189
                .setText(MTJUIMessages.PreverificationPreferencePage_preverifyConfigGroup_label_text);
190
        preverifyConfigGroup.setLayout(new GridLayout(1, false));
191
        preverifyConfigGroup.setLayoutData(new GridData(
192
                GridData.FILL_HORIZONTAL));
193
221
194
        preverificationRadios = new Button[BUTTON_TEXTS.length];
222
			if (CONFIG_FILE_LOCATIONS[i]
195
        for (int i = 0; i < BUTTON_TEXTS.length; i++) {
223
					.equals(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED)) {
196
            preverificationRadios[i] = new Button(preverifyConfigGroup,
224
				addSpecificConfigurationControls(preverifyConfigGroup);
197
                    SWT.RADIO);
225
			}
198
            preverificationRadios[i].setText(BUTTON_TEXTS[i]);
226
		}
227
	}
199
228
200
            if (CONFIG_FILE_LOCATIONS[i]
229
	/**
201
                    .equals(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED)) {
230
	 * Add the controls for setting the default preverifier.
202
                addSpecificConfigurationControls(preverifyConfigGroup);
231
	 * 
203
            }
232
	 * @param composite
204
        }
233
	 */
205
    }
234
	private void addDefaultPreverifierControls(Composite composite) {
235
		defaultPreverifierGroup = new Group(composite, SWT.NONE);
236
		defaultPreverifierGroup
237
				.setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierGroup_label_text);
238
		defaultPreverifierGroup.setLayout(new GridLayout(3, false));
239
		defaultPreverifierGroup.setLayoutData(new GridData(
240
				GridData.FILL_HORIZONTAL));
206
241
207
    /**
242
		Label tip = new Label(defaultPreverifierGroup, SWT.NONE);
208
     * Add the controls for setting the default preverifier.
243
		tip
209
     * 
244
				.setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierTip_label_text);
210
     * @param composite
245
		GridData gd = new GridData();
211
     */
246
		gd.horizontalSpan = 3;
212
    private void addDefaultPreverifierControls(Composite composite) {
247
		gd.verticalIndent = 10;
213
        Group defaultPreverifierGroup = new Group(composite, SWT.NONE);
248
		tip.setLayoutData(gd);
214
        defaultPreverifierGroup
215
                .setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierGroup_label_text);
216
        defaultPreverifierGroup.setLayout(new GridLayout(3, false));
217
        defaultPreverifierGroup.setLayoutData(new GridData(
218
                GridData.FILL_HORIZONTAL));
219
249
220
        Label tip = new Label(defaultPreverifierGroup, SWT.NONE);
250
		defaultPreverifierField = new FileFieldEditor(
221
        tip
251
				IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER,
222
                .setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierTip_label_text);
252
				MTJUIMessages.PreverificationPreferencePage_defaultPreverifierField_label_text,
223
        GridData gd = new GridData();
253
				defaultPreverifierGroup);
224
        gd.horizontalSpan = 3;
225
        gd.verticalIndent = 10;
226
        tip.setLayoutData(gd);
227
254
228
        defaultPreverifierField = new FileFieldEditor(
255
		String[] extensions = null;
229
                IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER,
256
		if (Platform.getOS().equals(Platform.OS_WIN32)) {
230
                MTJUIMessages.PreverificationPreferencePage_defaultPreverifierField_label_text,
257
			extensions = new String[] { "*.exe" }; //$NON-NLS-1$
231
                defaultPreverifierGroup);
258
		}
259
		defaultPreverifierField.setFileExtensions(extensions);
260
		defaultPreverifierField.setPreferenceStore(getPreferenceStore());
261
	}
232
262
233
        String[] extensions = null;
263
	/**
234
        if (Platform.getOS().equals(Platform.OS_WIN32)) {
264
	 * Add the configuration specific controls.
235
            extensions = new String[] { "*.exe" }; //$NON-NLS-1$
265
	 * 
236
        }
266
	 * @param preverifyConfigGroup
237
        defaultPreverifierField.setFileExtensions(extensions);
267
	 * @throws CoreException
238
        defaultPreverifierField.setPreferenceStore(getPreferenceStore());
268
	 */
239
    }
269
	private void addSpecificConfigurationControls(Group preverifyConfigGroup) {
270
		configCombo = new Combo(preverifyConfigGroup, SWT.READ_ONLY);
271
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
272
		gridData.horizontalIndent = 15;
273
		configCombo.setLayoutData(gridData);
240
274
241
    /**
275
		String[] displayValues = new String[configSpecs.length];
242
     * Add the configuration specific controls.
276
		for (int i = 0; i < displayValues.length; i++) {
243
     * 
277
			displayValues[i] = configSpecs[i].getName();
244
     * @param preverifyConfigGroup
278
		}
245
     * @throws CoreException
246
     */
247
    private void addSpecificConfigurationControls(Group preverifyConfigGroup) {
248
        configCombo = new Combo(preverifyConfigGroup, SWT.READ_ONLY);
249
        GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
250
        gridData.horizontalIndent = 15;
251
        configCombo.setLayoutData(gridData);
252
279
253
        String[] displayValues = new String[configSpecs.length];
280
		configCombo.setItems(displayValues);
254
        for (int i = 0; i < displayValues.length; i++) {
281
	}
255
            displayValues[i] = configSpecs[i].getName();
256
        }
257
282
258
        configCombo.setItems(displayValues);
283
	/**
259
    }
284
	 * Build the midlet suites in the workspace because preverification settings
285
	 * have changed.
286
	 */
287
	private void buildSuites() {
288
		// TODO Add some more smarts to what needs to get rebuilt.
289
		IWorkspaceRoot root = MTJCore.getWorkspace().getRoot();
290
		IProject[] projects = root.getProjects();
260
291
261
    /**
292
		ArrayList<IProject> toBuild = new ArrayList<IProject>();
262
     * Build the midlet suites in the workspace because preverification settings
263
     * have changed.
264
     */
265
    private void buildSuites() {
266
        // TODO Add some more smarts to what needs to get rebuilt.
267
        IWorkspaceRoot root = MTJCore.getWorkspace().getRoot();
268
        IProject[] projects = root.getProjects();
269
293
270
        ArrayList<IProject> toBuild = new ArrayList<IProject>();
294
		// Collect the projects to be built
295
		for (int i = 0; i < projects.length; i++) {
296
			IProject project = projects[i];
271
297
272
        // Collect the projects to be built
298
			try {
273
        for (int i = 0; i < projects.length; i++) {
299
				if (project.isOpen()
274
            IProject project = projects[i];
300
						&& project.hasNature(IMTJCoreConstants.MTJ_NATURE_ID)
301
						&& !usesProjectSpecificPreverification(project)) {
302
					toBuild.add(project);
303
				}
304
			} catch (CoreException e) {
305
				MTJLogger
306
						.log(
307
								IStatus.ERROR,
308
								MTJUIMessages.PreverificationPreferencePage_error_build_midlet_suite,
309
								e);
310
			}
311
		}
275
312
276
            try {
313
		// Do the build of those projects
277
                if (project.isOpen()
314
		IProject[] projectArray = toBuild.toArray(new IProject[toBuild.size()]);
278
                        && project.hasNature(IMTJCoreConstants.MTJ_NATURE_ID)
315
		if (projectArray.length > 0) {
279
                        && !usesProjectSpecificPreverification(project)) {
316
			doBuild(projectArray);
280
                    toBuild.add(project);
317
		}
281
                }
318
	}
282
            } catch (CoreException e) {
283
                MTJLogger
284
                        .log(
285
                                IStatus.ERROR,
286
                                MTJUIMessages.PreverificationPreferencePage_error_build_midlet_suite,
287
                                e);
288
            }
289
        }
290
319
291
        // Do the build of those projects
320
	private void setControlsFromDefaults() {
292
        IProject[] projectArray = toBuild.toArray(new IProject[toBuild.size()]);
321
		if (preverificationRadios != null) {
293
        if (projectArray.length > 0) {
322
			IPreferenceStore store = getPreferenceStore();
294
            doBuild(projectArray);
323
			String location = store
295
        }
324
					.getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
296
    }
325
			for (int i = 0; i < preverificationRadios.length; i++) {
326
				String fieldValue = CONFIG_FILE_LOCATIONS[i];
327
				preverificationRadios[i].setSelection(fieldValue
328
						.equals(location));
329
			}
330
			
331
			            
332
			IPreferenceStore preverifierTypestore = radioGroupFieldEditor
333
					.getPreferenceStore();
334
			
335
			String preverifyType = preverifierTypestore
336
					.getString(IMTJCoreConstants.PREF_PREVERIFY_TYPE);
337
			if (preverifyType.equals("preverify_default")) {
338
				defaultPreverifierField.setEnabled(true,
339
						defaultPreverifierGroup);
340
			} else {
341
				defaultPreverifierField.setEnabled(false,
342
						defaultPreverifierGroup);
343
			}
297
344
298
    private void setControlsFromDefaults() {
345
			int specIndex = 0;
299
        if (preverificationRadios != null) {
346
			String config = store
300
            IPreferenceStore store = getPreferenceStore();
347
					.getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
301
            String location = store
348
			for (int i = 0; i < configSpecs.length; i++) {
302
                    .getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
349
				IAPI spec = configSpecs[i];
303
            for (int i = 0; i < preverificationRadios.length; i++) {
350
				if (spec.getIdentifier().equals(config)) {
304
                String fieldValue = CONFIG_FILE_LOCATIONS[i];
351
					specIndex = i;
305
                preverificationRadios[i].setSelection(fieldValue
352
					break;
306
                        .equals(location));
353
				}
307
            }
354
			}
308
355
309
            int specIndex = 0;
356
			configCombo.select(specIndex);
310
            String config = store
357
		}
311
                    .getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
312
            for (int i = 0; i < configSpecs.length; i++) {
313
                IAPI spec = configSpecs[i];
314
                if (spec.toString().equals(config)) {
315
                    specIndex = i;
316
                    break;
317
                }
318
            }
319
358
320
            configCombo.select(specIndex);
359
		if (defaultPreverifierField != null) {
321
        }
360
			defaultPreverifierField.loadDefault();
361
		}
362
	}
322
363
323
        if (defaultPreverifierField != null) {
364
	/**
324
            defaultPreverifierField.loadDefault();
365
	 * Set the state of the controls based on the preferences.
325
        }
366
	 */
326
    }
367
	private void setControlsFromPreferences() {
368
		if (preverificationRadios != null) {
369
			IPreferenceStore store = getPreferenceStore();
370
			String location = store
371
					.getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
372
			for (int i = 0; i < preverificationRadios.length; i++) {
373
				String fieldValue = CONFIG_FILE_LOCATIONS[i];
374
				preverificationRadios[i].setSelection(fieldValue
375
						.equals(location));
376
			}
327
377
328
    /**
378
			IPreferenceStore preverifierTypestore = radioGroupFieldEditor
329
     * Set the state of the controls based on the preferences.
379
					.getPreferenceStore();
330
     */
380
			String asd = preverifierTypestore
331
    private void setControlsFromPreferences() {
381
					.getString(IMTJCoreConstants.PREF_PREVERIFY_TYPE);
332
        if (preverificationRadios != null) {
382
			if (asd.equals("preverify_default")) {
333
            IPreferenceStore store = getPreferenceStore();
383
				defaultPreverifierField.setEnabled(true,
334
            String location = store
384
						defaultPreverifierGroup);
335
                    .getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
385
			} else {
336
            for (int i = 0; i < preverificationRadios.length; i++) {
386
				defaultPreverifierField.setEnabled(false,
337
                String fieldValue = CONFIG_FILE_LOCATIONS[i];
387
						defaultPreverifierGroup);
338
                preverificationRadios[i].setSelection(fieldValue
388
			}
339
                        .equals(location));
340
            }
341
389
342
            int specIndex = 0;
390
			int specIndex = 0;
343
            String config = store
391
			String config = store
344
                    .getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
392
					.getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
345
            for (int i = 0; i < configSpecs.length; i++) {
393
			for (int i = 0; i < configSpecs.length; i++) {
346
                IAPI spec = configSpecs[i];
394
				IAPI spec = configSpecs[i];
347
                if (spec.toString().equals(config)) {
395
				if (spec.getIdentifier().equals(config)) {
348
                    specIndex = i;
396
					specIndex = i;
349
                    break;
397
					break;
350
                }
398
				}
351
            }
399
			}
352
400
353
            configCombo.select(specIndex);
401
			configCombo.select(specIndex);
354
        }
402
		}
355
        if (defaultPreverifierField != null) {
403
		if (defaultPreverifierField != null) {
356
            defaultPreverifierField.load();
404
			defaultPreverifierField.load();
357
        }
405
		}
358
    }
406
	}
359
407
360
    private void setDefaultPreverifier() {
408
	private void setDefaultPreverifier() {
361
        // if the default preverifier value changed
409
		// if the default preverifier value changed
362
        if (!defaultPreverifierField.getStringValue().equals(
410
		if (!defaultPreverifierField.getStringValue().equals(
363
                getPreferenceStore().getString(
411
				getPreferenceStore().getString(
364
                        IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER))) {
412
						IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER))) {
365
            File preverifierExecutable = new File(defaultPreverifierField
413
			File preverifierExecutable = new File(defaultPreverifierField
366
                    .getStringValue());
414
					.getStringValue());
367
            IPreverifier preverifier = null;
415
			IPreverifier preverifier = null;
368
            try {
416
			try {
369
                preverifier = MTJCore.createPreverifier(
417
				preverifier = MTJCore.createPreverifier(
370
                        IPreverifier.PREVERIFIER_STANDARD,
418
						IPreverifier.PREVERIFIER_STANDARD,
371
                        preverifierExecutable);
419
						preverifierExecutable);
372
            } catch (CoreException e) {
420
			} catch (CoreException e) {
373
                MTJUIPlugin
421
				MTJUIPlugin
374
                        .displayError(
422
						.displayError(
375
                                getShell(),
423
								getShell(),
376
                                IStatus.ERROR,
424
								IStatus.ERROR,
377
                                -999,
425
								-999,
378
                                MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_title,
426
								MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_title,
379
                                MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_message,
427
								MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_message,
380
                                e);
428
								e);
381
                MTJLogger
429
				MTJLogger
382
                        .log(
430
						.log(
383
                                IStatus.ERROR,
431
								IStatus.ERROR,
384
                                NLS
432
								NLS
385
                                        .bind(
433
										.bind(
386
                                                MTJUIMessages.PreverificationPreferencePage_device_store_error,
434
												MTJUIMessages.PreverificationPreferencePage_device_store_error,
387
                                                new String[] {
435
												new String[] {
388
                                                        e.getClass().getName(),
436
														e.getClass().getName(),
389
                                                        e.getMessage() }), e);
437
														e.getMessage() }), e);
390
            }
438
			}
391
            MTJCore.getDeviceRegistry().setDefaultPreverifer(preverifier);
439
			MTJCore.getDeviceRegistry().setDefaultPreverifer(preverifier);
392
440
393
            try {
441
			try {
394
                MTJCore.getDeviceRegistry().store();
442
				MTJCore.getDeviceRegistry().store();
395
            } catch (Exception e) {
443
			} catch (Exception e) {
396
                MTJUIPlugin
444
				MTJUIPlugin
397
                        .displayError(
445
						.displayError(
398
                                getShell(),
446
								getShell(),
399
                                IStatus.ERROR,
447
								IStatus.ERROR,
400
                                -999,
448
								-999,
401
                                MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_title,
449
								MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_title,
402
                                MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_message,
450
								MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_message,
403
                                e);
451
								e);
404
                MTJLogger
452
				MTJLogger
405
                        .log(
453
						.log(
406
                                IStatus.ERROR,
454
								IStatus.ERROR,
407
                                NLS
455
								NLS
408
                                        .bind(
456
										.bind(
409
                                                MTJUIMessages.PreverificationPreferencePage_device_store_error,
457
												MTJUIMessages.PreverificationPreferencePage_device_store_error,
410
                                                new String[] {
458
												new String[] {
411
                                                        e.getClass().getName(),
459
														e.getClass().getName(),
412
                                                        e.getMessage() }), e);
460
														e.getMessage() }), e);
413
            }
461
			}
414
        }
462
		}
415
463
416
    }
464
	}
417
465
418
    /**
466
	/**
419
     * Set the state of the preferences based on the controls.
467
	 * Set the state of the preferences based on the controls.
420
     */
468
	 */
421
    private void setPreferencesFromControls() {
469
	private void setPreferencesFromControls() {
422
        IPreferenceStore store = getPreferenceStore();
470
		IPreferenceStore store = getPreferenceStore();
423
        for (int i = 0; i < preverificationRadios.length; i++) {
471
		for (int i = 0; i < preverificationRadios.length; i++) {
424
            if (preverificationRadios[i].getSelection()) {
472
			if (preverificationRadios[i].getSelection()) {
425
                store.setValue(
473
				store.setValue(
426
                        IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION,
474
						IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION,
427
                        CONFIG_FILE_LOCATIONS[i]);
475
						CONFIG_FILE_LOCATIONS[i]);
428
                break;
476
				break;
429
            }
477
			}
430
        }
478
		}
431
479
432
        int index = configCombo.getSelectionIndex();
480
		int index = configCombo.getSelectionIndex();
433
        store.setValue(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE,
481
		store.setValue(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE,
434
                configSpecs[index].toString());
482
				configSpecs[index].getIdentifier());
435
        if (defaultPreverifierField != null) {
483
		if (defaultPreverifierField != null) {
436
            setDefaultPreverifier();
484
			setDefaultPreverifier();
437
            defaultPreverifierField.store();
485
			defaultPreverifierField.store();
438
        }
486
		}
439
    }
487
	}
440
488
441
    /**
489
	/**
442
     * Return a boolean indicating if the specified project is using
490
	 * Return a boolean indicating if the specified project is using
443
     * project-specific preverification settings.
491
	 * project-specific preverification settings.
444
     * 
492
	 * 
445
     * @param project
493
	 * @param project
446
     * @return
494
	 * @return
447
     */
495
	 */
448
    private boolean usesProjectSpecificPreverification(IProject project) {
496
	private boolean usesProjectSpecificPreverification(IProject project) {
449
        ProjectScope projectScope = new ProjectScope(project);
497
		ProjectScope projectScope = new ProjectScope(project);
450
        IEclipsePreferences prefNode = projectScope
498
		IEclipsePreferences prefNode = projectScope
451
                .getNode(IMTJCoreConstants.PLUGIN_ID);
499
				.getNode(IMTJCoreConstants.PLUGIN_ID);
452
500
453
        return prefNode.getBoolean(
501
		return prefNode.getBoolean(
454
                IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT, false);
502
				IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT, false);
455
    }
503
	}
456
504
457
    /* (non-Javadoc)
505
	/**
458
     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
506
	 * Add the controls that are for work-in-progress function.
459
     */
507
	 * 
460
    @Override
508
	 * @param composite
461
    protected Control createContents(Composite parent) {
509
	 */
510
	private void addTypeOfPreverifier(final Composite composite) {
511
		radioGroupFieldEditor = new RadioGroupFieldEditor(
512
				IMTJCoreConstants.PREF_PREVERIFY_TYPE,
513
				"Preverifier to use",
514
				1,
515
				new String[][] {
516
						{ "Default Preverifier",
517
								IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER },
518
						{ "Emulator Preverifier",
519
								IMTJCoreConstants.PREF_PREVERIFY_TYPE_EMULATOR },
520
						{ "Proguard Preverifier",
521
								IMTJCoreConstants.PREF_PREVERIFY_TYPE_PROGUARD } },
522
				composite, true);
523
		radioGroupFieldEditor.setPreferenceStore(getPreferenceStore());
524
		radioGroupFieldEditor.load();
525
		radioGroupFieldEditor.fillIntoGrid(composite, 1);
462
526
463
        Composite composite = new Composite(parent, SWT.NONE);
527
		radioGroupFieldEditor
464
        composite.setLayout(new GridLayout(1, false));
528
				.setPropertyChangeListener(new IPropertyChangeListener() {
465
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
529
					public void propertyChange(PropertyChangeEvent event) {
530
						String newValue = (String) event.getNewValue();
531
						if (!newValue.equals(event.getOldValue())) {
532
							if (newValue.equals("default_preverifier")) {
533
								defaultPreverifierField.setEnabled(true,
534
										defaultPreverifierGroup);
535
							} else if (newValue.equals("preverify_proguard")
536
									|| newValue.equals("preverify_emulator")) {
537
								defaultPreverifierField.setEnabled(false,
538
										defaultPreverifierGroup);
539
							}
540
						}
541
					}
542
				});
466
543
467
        addConfigurationControls(composite);
544
		// * "GeneralPage.DoubleClick", resName, 1,
545
		// * new String[][] {
546
		// * {"Open Browser", "open"},
547
		// * {"Expand Tree", "expand"}
548
		// * },
549
		// * parent
468
550
469
        if (!embeddedInProperties) {
551
		addField(radioGroupFieldEditor);
470
            addDefaultPreverifierControls(composite);
552
	}
471
        } else {
472
            noDefaultAndApplyButton();
473
        }
474
553
475
        setControlsFromPreferences();
554
	/*
555
	 * (non-Javadoc)
556
	 * 
557
	 * @see
558
	 * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse
559
	 * .swt.widgets.Composite)
560
	 */
561
	@Override
562
	protected Control createContents(Composite parent) {
476
563
477
        return composite;
564
		Composite composite = new Composite(parent, SWT.NONE);
478
    }
565
		composite.setLayout(new GridLayout(1, false));
566
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
567
568
		addConfigurationControls(composite);
569
570
		addTypeOfPreverifier(composite);
571
572
		if (!embeddedInProperties) {
573
			addDefaultPreverifierControls(composite);
574
		} else {
575
			noDefaultAndApplyButton();
576
		}
577
578
		setControlsFromPreferences();
579
580
		return composite;
581
	}
582
583
	private String getPreverifierType() {
584
		return PreferenceAccessor.instance.getPreverifierType(getProject());
585
586
	}
587
588
	public IProject getProject() {
589
		return javaProject.getProject();
590
	}
591
592
	@Override
593
	protected void createFieldEditors() {
594
		// TODO Auto-generated method stub
595
596
	}
479
}
597
}

Return to bug 234139