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 (-10 / +17 lines)
Lines 35-40 Link Here
35
 *     Fernando Rocha(Motorola) - Correct the update of the project classpath.
35
 *     Fernando Rocha(Motorola) - Correct the update of the project classpath.
36
 *     David Aragao (Motorola)  - Problem when try to import a project without 
36
 *     David Aragao (Motorola)  - Problem when try to import a project without 
37
 *     							  copy the files to the workspace. [Bug - 270157]
37
 *     							  copy the files to the workspace. [Bug - 270157]
38
 *     Gustavo de Paula (Motorola) - Add proguard preverifier options
39
 *     David Aragão (Motorola) - Add proguard preverifier refactoring
38
 */
40
 */
39
package org.eclipse.mtj.internal.core.project.midp;
41
package org.eclipse.mtj.internal.core.project.midp;
40
42
Lines 126-135 Link Here
126
	 */
128
	 */
127
	public static String getDefaultJadFileName(IProject project) {
129
	public static String getDefaultJadFileName(IProject project) {
128
		String projectName = project.getName();
130
		String projectName = project.getName();
129
		return NLS.bind(IMTJCoreConstants.VERSION_NLS_BIND_TEMPLATE,
131
		return NLS.bind("{0}.{1}", new String[] {
130
				new String[] { projectName.replace(' ', '_'),
132
				projectName.replace(' ', '_'), APP_DESCRIPTOR_FILE_EXT }); //$NON-NLS-1$
131
						APP_DESCRIPTOR_FILE_EXT }); //$NON-NLS-1$
132
133
	}
133
	}
134
134
135
	// The java project on which this MIDlet suite is based
135
	// The java project on which this MIDlet suite is based
Lines 167-173 Link Here
167
		initializeMetadata();
167
		initializeMetadata();
168
168
169
		MTJRuntime mtjRuntime = getRuntimeList().getActiveMTJRuntime();
169
		MTJRuntime mtjRuntime = getRuntimeList().getActiveMTJRuntime();
170
		if ((mtjRuntime != null) && (mtjRuntime.getDevice() == null)) {
170
		if (mtjRuntime != null && mtjRuntime.getDevice() == null) {
171
			try {
171
			try {
172
				if (getProject().findMarkers(
172
				if (getProject().findMarkers(
173
						IMTJCoreConstants.JAVAME_MISSING_DEVICE_MARKER, false,
173
						IMTJCoreConstants.JAVAME_MISSING_DEVICE_MARKER, false,
Lines 208-216 Link Here
208
	 * org.eclipse.mtj.core.project.IMTJProject#createPackage(org.eclipse.core
208
	 * org.eclipse.mtj.core.project.IMTJProject#createPackage(org.eclipse.core
209
	 * .runtime.IProgressMonitor, boolean, boolean)
209
	 * .runtime.IProgressMonitor, boolean, boolean)
210
	 */
210
	 */
211
	public void createPackage(boolean obfuscate,
211
	public void createPackage(IProgressMonitor monitor, boolean obfuscate,
212
			boolean packageInactiveConfigs, IProgressMonitor monitor)
212
			boolean packageInactiveConfigs) throws CoreException {
213
			throws CoreException {
214
213
215
		Map<String, String> args = new HashMap<String, String>();
214
		Map<String, String> args = new HashMap<String, String>();
216
		args.put(PackageBuilder.ARG_DO_PACKAGE, Boolean.TRUE.toString());
215
		args.put(PackageBuilder.ARG_DO_PACKAGE, Boolean.TRUE.toString());
Lines 226-232 Link Here
226
		BuildSpecManipulator manipulator = new BuildSpecManipulator(this
225
		BuildSpecManipulator manipulator = new BuildSpecManipulator(this
227
				.getProject());
226
				.getProject());
228
		// Set builder arguments
227
		// Set builder arguments
229
		manipulator.setBuilderArguments(IMTJCoreConstants.PACKAGE_BUILDER_ID,
228
		manipulator.setBuilderArguments(org.eclipse.mtj.internal.core.IMTJCoreConstants.PACKAGE_BUILDER_ID,
230
				args);
229
				args);
231
		manipulator.commitChanges(monitor);
230
		manipulator.commitChanges(monitor);
232
231
Lines 234-240 Link Here
234
		getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
233
		getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
235
		if (!packageInactiveConfigs) {
234
		if (!packageInactiveConfigs) {
236
			// Reset builder Arguments
235
			// Reset builder Arguments
237
			manipulator.setBuilderArguments(IMTJCoreConstants.PACKAGE_BUILDER_ID,
236
			manipulator.setBuilderArguments(org.eclipse.mtj.internal.core.IMTJCoreConstants.PACKAGE_BUILDER_ID,
238
					new HashMap<String, String>());
237
					new HashMap<String, String>());
239
			manipulator.commitChanges(monitor);
238
			manipulator.commitChanges(monitor);
240
		} else {
239
		} else {
Lines 915-918 Link Here
915
		getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
914
		getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
916
	}
915
	}
917
916
917
	@Override
918
	public void createPackage(boolean obfuscate,
919
			boolean packageInactiveConfigs, IProgressMonitor monitor)
920
			throws CoreException {
921
		// TODO Auto-generated method stub
922
		
923
	}
924
918
}
925
}
(-)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 / +9 lines)
Lines 12-17 Link Here
12
 *                                standards
12
 *                                standards
13
 *     Hugo Raniere (Motorola)  - Default value for default preverifier
13
 *     Hugo Raniere (Motorola)  - Default value for default preverifier
14
 *     Gang Ma      (Sybase)    - Default value for preprocess debug level
14
 *     Gang Ma      (Sybase)    - Default value for preprocess debug level
15
 *     David Aragão (Motorola) - Add proguard preverifier refactoring
16
 *
15
 */
17
 */
16
package org.eclipse.mtj.internal.core;
18
package org.eclipse.mtj.internal.core;
17
19
Lines 55-61 Link Here
55
    public static final String PREF_DEF_PREVERIFY_CONFIG_LOCATION = PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM;
57
    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$
58
    public static final String PREF_DEF_PREVERIFY_CONFIG_VALUE = ""; //$NON-NLS-1$
57
    public static final String PREF_DEF_DEFAULT_PREVERIFIER = ""; //$NON-NLS-1$
59
    public static final String PREF_DEF_DEFAULT_PREVERIFIER = ""; //$NON-NLS-1$
58
60
    //public static final boolean PREF_DEF_PREVERIFY_BUILT_IN = false;
61
    public static final String PREF_DEF_PREVERIFY_TYPE = IMTJCoreConstants.PREF_PREVERIFY_TYPE_EMULATOR;
62
    
59
    public static final String PREF_DEF_WTK_ROOT = ""; //$NON-NLS-1$
63
    public static final String PREF_DEF_WTK_ROOT = ""; //$NON-NLS-1$
60
    public static final String PREF_DEF_ANTENNA_JAR = ""; //$NON-NLS-1$
64
    public static final String PREF_DEF_ANTENNA_JAR = ""; //$NON-NLS-1$
61
65
Lines 103-111 Link Here
103
                PREF_DEF_PREVERIFY_CONFIG_LOCATION);
107
                PREF_DEF_PREVERIFY_CONFIG_LOCATION);
104
        prefs.setDefault(PREF_PREVERIFY_CONFIG_VALUE,
108
        prefs.setDefault(PREF_PREVERIFY_CONFIG_VALUE,
105
                PREF_DEF_PREVERIFY_CONFIG_VALUE);
109
                PREF_DEF_PREVERIFY_CONFIG_VALUE);
106
        prefs
110
        prefs.setDefault(PREF_PREVERIFY_CONFIG_VALUE,
107
                .setDefault(PREF_DEFAULT_PREVERIFIER,
111
        		PREF_DEF_PREVERIFY_TYPE);
108
                        PREF_DEF_DEFAULT_PREVERIFIER);
112
        prefs.setDefault(PREF_DEFAULT_PREVERIFIER,
113
                PREF_DEF_DEFAULT_PREVERIFIER);
109
114
110
        prefs.setDefault(PREF_ANTENNA_JAR, PREF_DEF_ANTENNA_JAR);
115
        prefs.setDefault(PREF_ANTENNA_JAR, PREF_DEF_ANTENNA_JAR);
111
        prefs.setDefault(PREF_WTK_ROOT, PREF_DEF_WTK_ROOT);
116
        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;
35
import org.eclipse.core.runtime.Platform;
34
import org.eclipse.core.runtime.SubProgressMonitor;
36
import org.eclipse.core.runtime.SubProgressMonitor;
35
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
37
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
38
import org.eclipse.jdt.core.IJavaProject;
36
import org.eclipse.jface.operation.IRunnableWithProgress;
39
import org.eclipse.jface.operation.IRunnableWithProgress;
40
import org.eclipse.jface.preference.FieldEditorPreferencePage;
37
import org.eclipse.jface.preference.FileFieldEditor;
41
import org.eclipse.jface.preference.FileFieldEditor;
38
import org.eclipse.jface.preference.IPreferenceStore;
42
import org.eclipse.jface.preference.IPreferenceStore;
39
import org.eclipse.jface.preference.PreferencePage;
43
import org.eclipse.jface.preference.RadioGroupFieldEditor;
44
import org.eclipse.jface.util.IPropertyChangeListener;
45
import org.eclipse.jface.util.PropertyChangeEvent;
40
import org.eclipse.mtj.core.MTJCore;
46
import org.eclipse.mtj.core.MTJCore;
41
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
47
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
42
import org.eclipse.mtj.core.sdk.device.IAPI;
48
import org.eclipse.mtj.core.sdk.device.IAPI;
Lines 41-46 Link Here
41
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
47
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
42
import org.eclipse.mtj.core.sdk.device.IAPI;
48
import org.eclipse.mtj.core.sdk.device.IAPI;
43
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
49
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
50
import org.eclipse.mtj.internal.core.PreferenceAccessor;
44
import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration;
51
import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration;
45
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
52
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
46
import org.eclipse.mtj.internal.ui.IEmbeddableWorkbenchPreferencePage;
53
import org.eclipse.mtj.internal.ui.IEmbeddableWorkbenchPreferencePage;
Lines 64-479 Link Here
64
 * 
71
 * 
65
 * @author Craig Setera
72
 * @author Craig Setera
66
 */
73
 */
67
public class PreverificationPreferencePage extends PreferencePage implements
74
public class PreverificationPreferencePage extends FieldEditorPreferencePage
68
        IEmbeddableWorkbenchPreferencePage {
75
		implements IEmbeddableWorkbenchPreferencePage {
76
77
	private static final String[] BUTTON_TEXTS = new String[] {
78
			MTJUIMessages.PreverificationPreferencePage_use_jad_settings_label_text,
79
			MTJUIMessages.PreverificationPreferencePage_use_project_settings_label_text,
80
			MTJUIMessages.PreverificationPreferencePage_use_specific_config_label_text, };
81
82
	private static final String[] CONFIG_FILE_LOCATIONS = new String[] {
83
			IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_JAD,
84
			IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_PLATFORM,
85
			IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED, };
86
87
	private Combo configCombo;
88
	private IAPI[] configSpecs;
89
	private FileFieldEditor defaultPreverifierField;
90
	private Group defaultPreverifierGroup;
91
	private boolean embeddedInProperties;
69
92
70
    private static final String[] BUTTON_TEXTS = new String[] {
93
	// The java project on which this MIDlet suite is based
71
            MTJUIMessages.PreverificationPreferencePage_use_jad_settings_label_text,
94
	private IJavaProject javaProject;
72
            MTJUIMessages.PreverificationPreferencePage_use_project_settings_label_text,
73
            MTJUIMessages.PreverificationPreferencePage_use_specific_config_label_text, };
74
95
75
    private static final String[] CONFIG_FILE_LOCATIONS = new String[] {
96
	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
97
80
    private Combo configCombo;
98
	private RadioGroupFieldEditor radioGroupFieldEditor;
81
    private IAPI[] configSpecs;
82
    private FileFieldEditor defaultPreverifierField;
83
    private boolean embeddedInProperties;
84
99
85
    private Button[] preverificationRadios;
100
	/**
101
	 * Default constructor.
102
	 */
103
	public PreverificationPreferencePage() {
104
		this(false, MTJUIPlugin.getDefault().getCorePreferenceStore());
105
	}
86
106
87
    /**
107
	/**
88
     * Default constructor.
108
	 * Constructor for use when embedding the preference page within a
89
     */
109
	 * properties page.
90
    public PreverificationPreferencePage() {
110
	 * 
91
        this(false, MTJUIPlugin.getDefault().getCorePreferenceStore());
111
	 * @param embeddedInProperties
92
    }
112
	 * @param preferenceStore
113
	 *            a table mapping named preferences to values
114
	 */
115
	public PreverificationPreferencePage(boolean embeddedInProperties,
116
			IPreferenceStore preferenceStore) {
93
117
94
    /**
118
		this.embeddedInProperties = embeddedInProperties;
95
     * Constructor for use when embedding the preference page within a
119
		setPreferenceStore(preferenceStore);
96
     * properties page.
120
		configSpecs = Configuration.values();
97
     * 
121
	}
98
     * @param embeddedInProperties
99
     * @param preferenceStore a table mapping named preferences to values
100
     */
101
    public PreverificationPreferencePage(boolean embeddedInProperties,
102
            IPreferenceStore preferenceStore) {
103
122
104
        this.embeddedInProperties = embeddedInProperties;
123
	/**
105
        setPreferenceStore(preferenceStore);
124
	 * Launch the build of the MIDlet suites.
106
        configSpecs = Configuration.values();
125
	 * 
107
    }
126
	 * @param toBuild
127
	 */
128
	public void doBuild(final IProject[] toBuild) {
129
		// The work to be done.
130
		IRunnableWithProgress runnable = new IRunnableWithProgress() {
131
			public void run(IProgressMonitor monitor)
132
					throws InvocationTargetException {
133
				try {
134
					for (int i = 0; i < toBuild.length; i++) {
135
						SubProgressMonitor subMonitor = new SubProgressMonitor(
136
								monitor, IProgressMonitor.UNKNOWN);
137
						toBuild[i].build(IncrementalProjectBuilder.FULL_BUILD,
138
								subMonitor);
139
						subMonitor.done();
140
					}
141
				} catch (CoreException e) {
142
					throw new InvocationTargetException(e);
143
				}
144
			}
145
		};
146
		try {
147
			PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
148
					runnable);
149
		} catch (InterruptedException e) {
150
		} catch (InvocationTargetException e) {
151
			MTJLogger
152
					.log(
153
							IStatus.WARNING,
154
							MTJUIMessages.PreverificationPreferencePage_error_build_suite,
155
							e.getCause());
156
		}
157
	}
108
158
109
    /**
159
	/*
110
     * Launch the build of the MIDlet suites.
160
	 * (non-Javadoc)
111
     * 
161
	 * 
112
     * @param toBuild
162
	 * @see
113
     */
163
	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
114
    public void doBuild(final IProject[] toBuild) {
164
	 */
115
        // The work to be done.
165
	public void init(IWorkbench workbench) {
116
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
166
	}
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
167
145
    /* (non-Javadoc)
168
	/*
146
     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
169
	 * (non-Javadoc)
147
     */
170
	 * 
148
    public void init(IWorkbench workbench) {
171
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
149
    }
172
	 */
173
	@Override
174
	public void performApply() {
175
		super.performApply();
176
	}
150
177
151
    /* (non-Javadoc)
178
	/*
152
     * @see org.eclipse.jface.preference.PreferencePage#performApply()
179
	 * (non-Javadoc)
153
     */
180
	 * 
154
    @Override
181
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
155
    public void performApply() {
182
	 */
156
        super.performApply();
183
	@Override
157
    }
184
	public void performDefaults() {
185
		setControlsFromDefaults();
186
		super.performDefaults();
187
	}
158
188
159
    /* (non-Javadoc)
189
	/*
160
     * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
190
	 * (non-Javadoc)
161
     */
191
	 * 
162
    @Override
192
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
163
    public void performDefaults() {
193
	 */
164
        setControlsFromDefaults();
194
	@Override
165
        super.performDefaults();
195
	public boolean performOk() {
166
    }
196
		setPreferencesFromControls();
197
		if (!embeddedInProperties) {
198
			buildSuites();
199
		}
167
200
168
    /* (non-Javadoc)
201
		return super.performOk();
169
     * @see org.eclipse.jface.preference.PreferencePage#performOk()
202
	}
170
     */
171
    @Override
172
    public boolean performOk() {
173
        setPreferencesFromControls();
174
        if (!embeddedInProperties) {
175
            buildSuites();
176
        }
177
203
178
        return super.performOk();
204
	/**
179
    }
205
	 * Add the controls for choosing the preverification configuration.
206
	 * 
207
	 * @param composite
208
	 */
209
	private void addConfigurationControls(Composite composite) {
210
		Group preverifyConfigGroup = new Group(composite, SWT.NONE);
211
		preverifyConfigGroup
212
				.setText(MTJUIMessages.PreverificationPreferencePage_preverifyConfigGroup_label_text);
213
		preverifyConfigGroup.setLayout(new GridLayout(1, false));
214
		preverifyConfigGroup.setLayoutData(new GridData(
215
				GridData.FILL_HORIZONTAL));
180
216
181
    /**
217
		preverificationRadios = new Button[BUTTON_TEXTS.length];
182
     * Add the controls for choosing the preverification configuration.
218
		for (int i = 0; i < BUTTON_TEXTS.length; i++) {
183
     * 
219
			preverificationRadios[i] = new Button(preverifyConfigGroup,
184
     * @param composite
220
					SWT.RADIO);
185
     */
221
			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
222
194
        preverificationRadios = new Button[BUTTON_TEXTS.length];
223
			if (CONFIG_FILE_LOCATIONS[i]
195
        for (int i = 0; i < BUTTON_TEXTS.length; i++) {
224
					.equals(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED)) {
196
            preverificationRadios[i] = new Button(preverifyConfigGroup,
225
				addSpecificConfigurationControls(preverifyConfigGroup);
197
                    SWT.RADIO);
226
			}
198
            preverificationRadios[i].setText(BUTTON_TEXTS[i]);
227
		}
228
	}
199
229
200
            if (CONFIG_FILE_LOCATIONS[i]
230
	/**
201
                    .equals(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION_SPECIFIED)) {
231
	 * Add the controls for setting the default preverifier.
202
                addSpecificConfigurationControls(preverifyConfigGroup);
232
	 * 
203
            }
233
	 * @param composite
204
        }
234
	 */
205
    }
235
	private void addDefaultPreverifierControls(Composite composite) {
236
		defaultPreverifierGroup = new Group(composite, SWT.NONE);
237
		defaultPreverifierGroup
238
				.setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierGroup_label_text);
239
		defaultPreverifierGroup.setLayout(new GridLayout(3, false));
240
		defaultPreverifierGroup.setLayoutData(new GridData(
241
				GridData.FILL_HORIZONTAL));
206
242
207
    /**
243
		Label tip = new Label(defaultPreverifierGroup, SWT.NONE);
208
     * Add the controls for setting the default preverifier.
244
		tip
209
     * 
245
				.setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierTip_label_text);
210
     * @param composite
246
		GridData gd = new GridData();
211
     */
247
		gd.horizontalSpan = 3;
212
    private void addDefaultPreverifierControls(Composite composite) {
248
		gd.verticalIndent = 10;
213
        Group defaultPreverifierGroup = new Group(composite, SWT.NONE);
249
		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
250
220
        Label tip = new Label(defaultPreverifierGroup, SWT.NONE);
251
		defaultPreverifierField = new FileFieldEditor(
221
        tip
252
				IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER,
222
                .setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierTip_label_text);
253
				MTJUIMessages.PreverificationPreferencePage_defaultPreverifierField_label_text,
223
        GridData gd = new GridData();
254
				defaultPreverifierGroup);
224
        gd.horizontalSpan = 3;
225
        gd.verticalIndent = 10;
226
        tip.setLayoutData(gd);
227
255
228
        defaultPreverifierField = new FileFieldEditor(
256
		String[] extensions = null;
229
                IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER,
257
		if (Platform.getOS().equals(Platform.OS_WIN32)) {
230
                MTJUIMessages.PreverificationPreferencePage_defaultPreverifierField_label_text,
258
			extensions = new String[] { "*.exe" }; //$NON-NLS-1$
231
                defaultPreverifierGroup);
259
		}
260
		defaultPreverifierField.setFileExtensions(extensions);
261
		defaultPreverifierField.setPreferenceStore(getPreferenceStore());
262
	}
232
263
233
        String[] extensions = null;
264
	/**
234
        if (Platform.getOS().equals(Platform.OS_WIN32)) {
265
	 * Add the configuration specific controls.
235
            extensions = new String[] { "*.exe" }; //$NON-NLS-1$
266
	 * 
236
        }
267
	 * @param preverifyConfigGroup
237
        defaultPreverifierField.setFileExtensions(extensions);
268
	 * @throws CoreException
238
        defaultPreverifierField.setPreferenceStore(getPreferenceStore());
269
	 */
239
    }
270
	private void addSpecificConfigurationControls(Group preverifyConfigGroup) {
271
		configCombo = new Combo(preverifyConfigGroup, SWT.READ_ONLY);
272
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
273
		gridData.horizontalIndent = 15;
274
		configCombo.setLayoutData(gridData);
240
275
241
    /**
276
		String[] displayValues = new String[configSpecs.length];
242
     * Add the configuration specific controls.
277
		for (int i = 0; i < displayValues.length; i++) {
243
     * 
278
			displayValues[i] = configSpecs[i].getName();
244
     * @param preverifyConfigGroup
279
		}
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
280
253
        String[] displayValues = new String[configSpecs.length];
281
		configCombo.setItems(displayValues);
254
        for (int i = 0; i < displayValues.length; i++) {
282
	}
255
            displayValues[i] = configSpecs[i].getName();
256
        }
257
283
258
        configCombo.setItems(displayValues);
284
	/**
259
    }
285
	 * Build the midlet suites in the workspace because preverification settings
286
	 * have changed.
287
	 */
288
	private void buildSuites() {
289
		// TODO Add some more smarts to what needs to get rebuilt.
290
		IWorkspaceRoot root = MTJCore.getWorkspace().getRoot();
291
		IProject[] projects = root.getProjects();
260
292
261
    /**
293
		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
294
270
        ArrayList<IProject> toBuild = new ArrayList<IProject>();
295
		// Collect the projects to be built
296
		for (int i = 0; i < projects.length; i++) {
297
			IProject project = projects[i];
271
298
272
        // Collect the projects to be built
299
			try {
273
        for (int i = 0; i < projects.length; i++) {
300
				if (project.isOpen()
274
            IProject project = projects[i];
301
						&& project.hasNature(IMTJCoreConstants.MTJ_NATURE_ID)
302
						&& !usesProjectSpecificPreverification(project)) {
303
					toBuild.add(project);
304
				}
305
			} catch (CoreException e) {
306
				MTJLogger
307
						.log(
308
								IStatus.ERROR,
309
								MTJUIMessages.PreverificationPreferencePage_error_build_midlet_suite,
310
								e);
311
			}
312
		}
275
313
276
            try {
314
		// Do the build of those projects
277
                if (project.isOpen()
315
		IProject[] projectArray = toBuild.toArray(new IProject[toBuild.size()]);
278
                        && project.hasNature(IMTJCoreConstants.MTJ_NATURE_ID)
316
		if (projectArray.length > 0) {
279
                        && !usesProjectSpecificPreverification(project)) {
317
			doBuild(projectArray);
280
                    toBuild.add(project);
318
		}
281
                }
319
	}
282
            } catch (CoreException e) {
283
                MTJLogger
284
                        .log(
285
                                IStatus.ERROR,
286
                                MTJUIMessages.PreverificationPreferencePage_error_build_midlet_suite,
287
                                e);
288
            }
289
        }
290
320
291
        // Do the build of those projects
321
	private void setControlsFromDefaults() {
292
        IProject[] projectArray = toBuild.toArray(new IProject[toBuild.size()]);
322
		if (preverificationRadios != null) {
293
        if (projectArray.length > 0) {
323
			IPreferenceStore store = getPreferenceStore();
294
            doBuild(projectArray);
324
			String location = store
295
        }
325
					.getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
296
    }
326
			for (int i = 0; i < preverificationRadios.length; i++) {
327
				String fieldValue = CONFIG_FILE_LOCATIONS[i];
328
				preverificationRadios[i].setSelection(fieldValue
329
						.equals(location));
330
			}
331
			
332
			            
333
			IPreferenceStore preverifierTypestore = radioGroupFieldEditor
334
					.getPreferenceStore();
335
			
336
			String preverifyType = preverifierTypestore
337
					.getString(IMTJCoreConstants.PREF_PREVERIFY_TYPE);
338
			if (preverifyType.equals("preverify_default")) {
339
				defaultPreverifierField.setEnabled(true,
340
						defaultPreverifierGroup);
341
			} else {
342
				defaultPreverifierField.setEnabled(false,
343
						defaultPreverifierGroup);
344
			}
297
345
298
    private void setControlsFromDefaults() {
346
			int specIndex = 0;
299
        if (preverificationRadios != null) {
347
			String config = store
300
            IPreferenceStore store = getPreferenceStore();
348
					.getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
301
            String location = store
349
			for (int i = 0; i < configSpecs.length; i++) {
302
                    .getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
350
				IAPI spec = configSpecs[i];
303
            for (int i = 0; i < preverificationRadios.length; i++) {
351
				if (spec.getIdentifier().equals(config)) {
304
                String fieldValue = CONFIG_FILE_LOCATIONS[i];
352
					specIndex = i;
305
                preverificationRadios[i].setSelection(fieldValue
353
					break;
306
                        .equals(location));
354
				}
307
            }
355
			}
308
356
309
            int specIndex = 0;
357
			configCombo.select(specIndex);
310
            String config = store
358
		}
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
359
320
            configCombo.select(specIndex);
360
		if (defaultPreverifierField != null) {
321
        }
361
			defaultPreverifierField.loadDefault();
362
		}
363
	}
322
364
323
        if (defaultPreverifierField != null) {
365
	/**
324
            defaultPreverifierField.loadDefault();
366
	 * Set the state of the controls based on the preferences.
325
        }
367
	 */
326
    }
368
	private void setControlsFromPreferences() {
369
		if (preverificationRadios != null) {
370
			IPreferenceStore store = getPreferenceStore();
371
			String location = store
372
					.getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
373
			for (int i = 0; i < preverificationRadios.length; i++) {
374
				String fieldValue = CONFIG_FILE_LOCATIONS[i];
375
				preverificationRadios[i].setSelection(fieldValue
376
						.equals(location));
377
			}
327
378
328
    /**
379
			IPreferenceStore preverifierTypestore = radioGroupFieldEditor
329
     * Set the state of the controls based on the preferences.
380
					.getPreferenceStore();
330
     */
381
			String asd = preverifierTypestore
331
    private void setControlsFromPreferences() {
382
					.getString(IMTJCoreConstants.PREF_PREVERIFY_TYPE);
332
        if (preverificationRadios != null) {
383
			if (asd.equals("preverify_default")) {
333
            IPreferenceStore store = getPreferenceStore();
384
				defaultPreverifierField.setEnabled(true,
334
            String location = store
385
						defaultPreverifierGroup);
335
                    .getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION);
386
			} else {
336
            for (int i = 0; i < preverificationRadios.length; i++) {
387
				defaultPreverifierField.setEnabled(false,
337
                String fieldValue = CONFIG_FILE_LOCATIONS[i];
388
						defaultPreverifierGroup);
338
                preverificationRadios[i].setSelection(fieldValue
389
			}
339
                        .equals(location));
340
            }
341
390
342
            int specIndex = 0;
391
			int specIndex = 0;
343
            String config = store
392
			String config = store
344
                    .getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
393
					.getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
345
            for (int i = 0; i < configSpecs.length; i++) {
394
			for (int i = 0; i < configSpecs.length; i++) {
346
                IAPI spec = configSpecs[i];
395
				IAPI spec = configSpecs[i];
347
                if (spec.toString().equals(config)) {
396
				if (spec.getIdentifier().equals(config)) {
348
                    specIndex = i;
397
					specIndex = i;
349
                    break;
398
					break;
350
                }
399
				}
351
            }
400
			}
352
401
353
            configCombo.select(specIndex);
402
			configCombo.select(specIndex);
354
        }
403
		}
355
        if (defaultPreverifierField != null) {
404
		if (defaultPreverifierField != null) {
356
            defaultPreverifierField.load();
405
			defaultPreverifierField.load();
357
        }
406
		}
358
    }
407
	}
359
408
360
    private void setDefaultPreverifier() {
409
	private void setDefaultPreverifier() {
361
        // if the default preverifier value changed
410
		// if the default preverifier value changed
362
        if (!defaultPreverifierField.getStringValue().equals(
411
		if (!defaultPreverifierField.getStringValue().equals(
363
                getPreferenceStore().getString(
412
				getPreferenceStore().getString(
364
                        IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER))) {
413
						IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER))) {
365
            File preverifierExecutable = new File(defaultPreverifierField
414
			File preverifierExecutable = new File(defaultPreverifierField
366
                    .getStringValue());
415
					.getStringValue());
367
            IPreverifier preverifier = null;
416
			IPreverifier preverifier = null;
368
            try {
417
			try {
369
                preverifier = MTJCore.createPreverifier(
418
				preverifier = MTJCore.createPreverifier(
370
                        IPreverifier.PREVERIFIER_STANDARD,
419
						IPreverifier.PREVERIFIER_STANDARD,
371
                        preverifierExecutable);
420
						preverifierExecutable);
372
            } catch (CoreException e) {
421
			} catch (CoreException e) {
373
                MTJUIPlugin
422
				MTJUIPlugin
374
                        .displayError(
423
						.displayError(
375
                                getShell(),
424
								getShell(),
376
                                IStatus.ERROR,
425
								IStatus.ERROR,
377
                                -999,
426
								-999,
378
                                MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_title,
427
								MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_title,
379
                                MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_message,
428
								MTJUIMessages.PreverificationPreferencePage_invalid_preverifier_dialog_message,
380
                                e);
429
								e);
381
                MTJLogger
430
				MTJLogger
382
                        .log(
431
						.log(
383
                                IStatus.ERROR,
432
								IStatus.ERROR,
384
                                NLS
433
								NLS
385
                                        .bind(
434
										.bind(
386
                                                MTJUIMessages.PreverificationPreferencePage_device_store_error,
435
												MTJUIMessages.PreverificationPreferencePage_device_store_error,
387
                                                new String[] {
436
												new String[] {
388
                                                        e.getClass().getName(),
437
														e.getClass().getName(),
389
                                                        e.getMessage() }), e);
438
														e.getMessage() }), e);
390
            }
439
			}
391
            MTJCore.getDeviceRegistry().setDefaultPreverifer(preverifier);
440
			MTJCore.getDeviceRegistry().setDefaultPreverifer(preverifier);
392
441
393
            try {
442
			try {
394
                MTJCore.getDeviceRegistry().store();
443
				MTJCore.getDeviceRegistry().store();
395
            } catch (Exception e) {
444
			} catch (Exception e) {
396
                MTJUIPlugin
445
				MTJUIPlugin
397
                        .displayError(
446
						.displayError(
398
                                getShell(),
447
								getShell(),
399
                                IStatus.ERROR,
448
								IStatus.ERROR,
400
                                -999,
449
								-999,
401
                                MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_title,
450
								MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_title,
402
                                MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_message,
451
								MTJUIMessages.PreverificationPreferencePage_error_store_preverifier_dialog_message,
403
                                e);
452
								e);
404
                MTJLogger
453
				MTJLogger
405
                        .log(
454
						.log(
406
                                IStatus.ERROR,
455
								IStatus.ERROR,
407
                                NLS
456
								NLS
408
                                        .bind(
457
										.bind(
409
                                                MTJUIMessages.PreverificationPreferencePage_device_store_error,
458
												MTJUIMessages.PreverificationPreferencePage_device_store_error,
410
                                                new String[] {
459
												new String[] {
411
                                                        e.getClass().getName(),
460
														e.getClass().getName(),
412
                                                        e.getMessage() }), e);
461
														e.getMessage() }), e);
413
            }
462
			}
414
        }
463
		}
415
464
416
    }
465
	}
417
466
418
    /**
467
	/**
419
     * Set the state of the preferences based on the controls.
468
	 * Set the state of the preferences based on the controls.
420
     */
469
	 */
421
    private void setPreferencesFromControls() {
470
	private void setPreferencesFromControls() {
422
        IPreferenceStore store = getPreferenceStore();
471
		IPreferenceStore store = getPreferenceStore();
423
        for (int i = 0; i < preverificationRadios.length; i++) {
472
		for (int i = 0; i < preverificationRadios.length; i++) {
424
            if (preverificationRadios[i].getSelection()) {
473
			if (preverificationRadios[i].getSelection()) {
425
                store.setValue(
474
				store.setValue(
426
                        IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION,
475
						IMTJCoreConstants.PREF_PREVERIFY_CONFIG_LOCATION,
427
                        CONFIG_FILE_LOCATIONS[i]);
476
						CONFIG_FILE_LOCATIONS[i]);
428
                break;
477
				break;
429
            }
478
			}
430
        }
479
		}
431
480
432
        int index = configCombo.getSelectionIndex();
481
		int index = configCombo.getSelectionIndex();
433
        store.setValue(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE,
482
		store.setValue(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE,
434
                configSpecs[index].toString());
483
				configSpecs[index].getIdentifier());
435
        if (defaultPreverifierField != null) {
484
		if (defaultPreverifierField != null) {
436
            setDefaultPreverifier();
485
			setDefaultPreverifier();
437
            defaultPreverifierField.store();
486
			defaultPreverifierField.store();
438
        }
487
		}
439
    }
488
	}
440
489
441
    /**
490
	/**
442
     * Return a boolean indicating if the specified project is using
491
	 * Return a boolean indicating if the specified project is using
443
     * project-specific preverification settings.
492
	 * project-specific preverification settings.
444
     * 
493
	 * 
445
     * @param project
494
	 * @param project
446
     * @return
495
	 * @return
447
     */
496
	 */
448
    private boolean usesProjectSpecificPreverification(IProject project) {
497
	private boolean usesProjectSpecificPreverification(IProject project) {
449
        ProjectScope projectScope = new ProjectScope(project);
498
		ProjectScope projectScope = new ProjectScope(project);
450
        IEclipsePreferences prefNode = projectScope
499
		IEclipsePreferences prefNode = projectScope
451
                .getNode(IMTJCoreConstants.PLUGIN_ID);
500
				.getNode(IMTJCoreConstants.PLUGIN_ID);
452
501
453
        return prefNode.getBoolean(
502
		return prefNode.getBoolean(
454
                IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT, false);
503
				IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT, false);
455
    }
504
	}
456
505
457
    /* (non-Javadoc)
506
	/**
458
     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
507
	 * Add the controls that are for work-in-progress function.
459
     */
508
	 * 
460
    @Override
509
	 * @param composite
461
    protected Control createContents(Composite parent) {
510
	 */
511
	private void addTypeOfPreverifier(final Composite composite) {
512
		radioGroupFieldEditor = new RadioGroupFieldEditor(
513
				IMTJCoreConstants.PREF_PREVERIFY_TYPE,
514
				"Preverifier to use",
515
				1,
516
				new String[][] {
517
						{ "Default Preverifier",
518
								IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER },
519
						{ "Emulator Preverifier",
520
								IMTJCoreConstants.PREF_PREVERIFY_TYPE_EMULATOR },
521
						{ "Proguard Preverifier",
522
								IMTJCoreConstants.PREF_PREVERIFY_TYPE_PROGUARD } },
523
				composite, true);
524
		radioGroupFieldEditor.setPreferenceStore(getPreferenceStore());
525
		radioGroupFieldEditor.load();
526
		radioGroupFieldEditor.fillIntoGrid(composite, 1);
462
527
463
        Composite composite = new Composite(parent, SWT.NONE);
528
		radioGroupFieldEditor
464
        composite.setLayout(new GridLayout(1, false));
529
				.setPropertyChangeListener(new IPropertyChangeListener() {
465
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
530
					public void propertyChange(PropertyChangeEvent event) {
531
						String newValue = (String) event.getNewValue();
532
						if (!newValue.equals(event.getOldValue())) {
533
							if (newValue.equals("default_preverifier")) {
534
								defaultPreverifierField.setEnabled(true,
535
										defaultPreverifierGroup);
536
							} else if (newValue.equals("preverify_proguard")
537
									|| newValue.equals("preverify_emulator")) {
538
								defaultPreverifierField.setEnabled(false,
539
										defaultPreverifierGroup);
540
							}
541
						}
542
					}
543
				});
466
544
467
        addConfigurationControls(composite);
545
		// * "GeneralPage.DoubleClick", resName, 1,
546
		// * new String[][] {
547
		// * {"Open Browser", "open"},
548
		// * {"Expand Tree", "expand"}
549
		// * },
550
		// * parent
468
551
469
        if (!embeddedInProperties) {
552
		addField(radioGroupFieldEditor);
470
            addDefaultPreverifierControls(composite);
553
	}
471
        } else {
472
            noDefaultAndApplyButton();
473
        }
474
554
475
        setControlsFromPreferences();
555
	/*
556
	 * (non-Javadoc)
557
	 * 
558
	 * @see
559
	 * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse
560
	 * .swt.widgets.Composite)
561
	 */
562
	@Override
563
	protected Control createContents(Composite parent) {
476
564
477
        return composite;
565
		Composite composite = new Composite(parent, SWT.NONE);
478
    }
566
		composite.setLayout(new GridLayout(1, false));
567
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
568
569
		addConfigurationControls(composite);
570
571
		addTypeOfPreverifier(composite);
572
573
		if (!embeddedInProperties) {
574
			addDefaultPreverifierControls(composite);
575
		} else {
576
			noDefaultAndApplyButton();
577
		}
578
579
		setControlsFromPreferences();
580
581
		return composite;
582
	}
583
584
	private String getPreverifierType() {
585
		return PreferenceAccessor.instance.getPreverifierType(getProject());
586
587
	}
588
589
	public IProject getProject() {
590
		return javaProject.getProject();
591
	}
592
593
	@Override
594
	protected void createFieldEditors() {
595
		// TODO Auto-generated method stub
596
597
	}
479
}
598
}

Return to bug 234139