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 / +5 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_BUILTIN = "preverify_builtin"; //$NON-NLS-1$
82
    public static final String PREF_PREVERIFY_TYPE_PROGUARD = "preverify_proguard"; //$NON-NLS-1$
83
    
80
    public static final String PREF_PREVERIFY_CONFIG_LOCATION_JAD = "jad"; //$NON-NLS-1$
84
    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$
85
    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$
86
    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 (-10 / +93 lines)
Lines 27-33 Link Here
27
import org.eclipse.core.resources.IWorkspaceRoot;
27
import org.eclipse.core.resources.IWorkspaceRoot;
28
import org.eclipse.core.resources.IncrementalProjectBuilder;
28
import org.eclipse.core.resources.IncrementalProjectBuilder;
29
import org.eclipse.core.resources.ProjectScope;
29
import org.eclipse.core.resources.ProjectScope;
30
import org.eclipse.core.resources.ResourcesPlugin;
31
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.core.runtime.IProgressMonitor;
33
import org.eclipse.core.runtime.IStatus;
32
import org.eclipse.core.runtime.IStatus;
Lines 34-47 Link Here
34
import org.eclipse.core.runtime.Platform;
33
import org.eclipse.core.runtime.Platform;
35
import org.eclipse.core.runtime.SubProgressMonitor;
34
import org.eclipse.core.runtime.SubProgressMonitor;
36
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
35
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
36
import org.eclipse.jdt.core.IJavaProject;
37
import org.eclipse.jface.operation.IRunnableWithProgress;
37
import org.eclipse.jface.operation.IRunnableWithProgress;
38
import org.eclipse.jface.preference.FieldEditorPreferencePage;
38
import org.eclipse.jface.preference.FileFieldEditor;
39
import org.eclipse.jface.preference.FileFieldEditor;
39
import org.eclipse.jface.preference.IPreferenceStore;
40
import org.eclipse.jface.preference.IPreferenceStore;
40
import org.eclipse.jface.preference.PreferencePage;
41
import org.eclipse.jface.preference.PreferencePage;
42
import org.eclipse.mtj.core.IMTJCoreConstants;
41
import org.eclipse.mtj.core.MTJCore;
43
import org.eclipse.mtj.core.MTJCore;
42
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
44
import org.eclipse.mtj.core.build.preverifier.IPreverifier;
43
import org.eclipse.mtj.core.sdk.device.IAPI;
45
import org.eclipse.mtj.core.sdk.device.IAPI;
44
import org.eclipse.mtj.internal.core.IMTJCoreConstants;
46
import org.eclipse.mtj.internal.core.PreferenceAccessor;
45
import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration;
47
import org.eclipse.mtj.internal.core.sdk.device.midp.Configuration;
46
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
48
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
47
import org.eclipse.mtj.internal.ui.IEmbeddableWorkbenchPreferencePage;
49
import org.eclipse.mtj.internal.ui.IEmbeddableWorkbenchPreferencePage;
Lines 59-64 Link Here
59
import org.eclipse.swt.widgets.Label;
61
import org.eclipse.swt.widgets.Label;
60
import org.eclipse.ui.IWorkbench;
62
import org.eclipse.ui.IWorkbench;
61
import org.eclipse.ui.PlatformUI;
63
import org.eclipse.ui.PlatformUI;
64
import org.eclipse.jface.preference.RadioGroupFieldEditor;
65
import org.eclipse.jface.util.IPropertyChangeListener;
66
import org.eclipse.jface.util.PropertyChangeEvent;
62
67
63
/**
68
/**
64
 * Preference page implementation for setting preverification preferences.
69
 * Preference page implementation for setting preverification preferences.
Lines 64-71 Link Here
64
 * Preference page implementation for setting preverification preferences.
69
 * Preference page implementation for setting preverification preferences.
65
 * 
70
 * 
66
 * @author Craig Setera
71
 * @author Craig Setera
72
 *         Gustavo de Paula (Motorola) - Change preverification to add proguard support
67
 */
73
 */
68
public class PreverificationPreferencePage extends PreferencePage implements
74
public class PreverificationPreferencePage extends FieldEditorPreferencePage implements
69
        IEmbeddableWorkbenchPreferencePage {
75
        IEmbeddableWorkbenchPreferencePage {
70
76
71
    private static final String[] BUTTON_TEXTS = new String[] {
77
    private static final String[] BUTTON_TEXTS = new String[] {
Lines 81-89 Link Here
81
    private Combo configCombo;
87
    private Combo configCombo;
82
    private IAPI[] configSpecs;
88
    private IAPI[] configSpecs;
83
    private FileFieldEditor defaultPreverifierField;
89
    private FileFieldEditor defaultPreverifierField;
90
    private Group defaultPreverifierGroup;
84
    private boolean embeddedInProperties;
91
    private boolean embeddedInProperties;
92
    
93
    // The java project on which this MIDlet suite is based
94
    private IJavaProject javaProject;
85
95
86
    private Button[] preverificationRadios;
96
    private Button[] preverificationRadios;
97
    
98
    private RadioGroupFieldEditor radioGroupFieldEditor;
87
99
88
    /**
100
    /**
89
     * Default constructor.
101
     * Default constructor.
Lines 211-217 Link Here
211
     * @param composite
223
     * @param composite
212
     */
224
     */
213
    private void addDefaultPreverifierControls(Composite composite) {
225
    private void addDefaultPreverifierControls(Composite composite) {
214
        Group defaultPreverifierGroup = new Group(composite, SWT.NONE);
226
        defaultPreverifierGroup = new Group(composite, SWT.NONE);
215
        defaultPreverifierGroup
227
        defaultPreverifierGroup
216
                .setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierGroup_label_text);
228
                .setText(MTJUIMessages.PreverificationPreferencePage_defaultPreverifierGroup_label_text);
217
        defaultPreverifierGroup.setLayout(new GridLayout(3, false));
229
        defaultPreverifierGroup.setLayout(new GridLayout(3, false));
Lines 230-236 Link Here
230
                IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER,
242
                IMTJCoreConstants.PREF_DEFAULT_PREVERIFIER,
231
                MTJUIMessages.PreverificationPreferencePage_defaultPreverifierField_label_text,
243
                MTJUIMessages.PreverificationPreferencePage_defaultPreverifierField_label_text,
232
                defaultPreverifierGroup);
244
                defaultPreverifierGroup);
233
245
        
234
        String[] extensions = null;
246
        String[] extensions = null;
235
        if (Platform.getOS().equals(Platform.OS_WIN32)) {
247
        if (Platform.getOS().equals(Platform.OS_WIN32)) {
236
            extensions = new String[] { "*.exe" }; //$NON-NLS-1$
248
            extensions = new String[] { "*.exe" }; //$NON-NLS-1$
Lines 312-318 Link Here
312
                    .getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
324
                    .getDefaultString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
313
            for (int i = 0; i < configSpecs.length; i++) {
325
            for (int i = 0; i < configSpecs.length; i++) {
314
                IAPI spec = configSpecs[i];
326
                IAPI spec = configSpecs[i];
315
                if (spec.toString().equals(config)) {
327
                if (spec.getIdentifier().equals(config)) {
316
                    specIndex = i;
328
                    specIndex = i;
317
                    break;
329
                    break;
318
                }
330
                }
Lines 339-344 Link Here
339
                preverificationRadios[i].setSelection(fieldValue
351
                preverificationRadios[i].setSelection(fieldValue
340
                        .equals(location));
352
                        .equals(location));
341
            }
353
            }
354
            
355
            IPreferenceStore preverifierTypestore = radioGroupFieldEditor.getPreferenceStore();
356
            String asd = preverifierTypestore.getString(IMTJCoreConstants.PREF_PREVERIFY_TYPE);
357
            if (asd.equals("preverify_default")) {
358
				defaultPreverifierField.setEnabled(true, defaultPreverifierGroup);
359
			}else {
360
				defaultPreverifierField.setEnabled(false, defaultPreverifierGroup);
361
			}
342
362
343
            int specIndex = 0;
363
            int specIndex = 0;
344
            String config = store
364
            String config = store
Lines 345-351 Link Here
345
                    .getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
365
                    .getString(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE);
346
            for (int i = 0; i < configSpecs.length; i++) {
366
            for (int i = 0; i < configSpecs.length; i++) {
347
                IAPI spec = configSpecs[i];
367
                IAPI spec = configSpecs[i];
348
                if (spec.toString().equals(config)) {
368
                if (spec.getIdentifier().equals(config)) {
349
                    specIndex = i;
369
                    specIndex = i;
350
                    break;
370
                    break;
351
                }
371
                }
Lines 432-438 Link Here
432
452
433
        int index = configCombo.getSelectionIndex();
453
        int index = configCombo.getSelectionIndex();
434
        store.setValue(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE,
454
        store.setValue(IMTJCoreConstants.PREF_PREVERIFY_CONFIG_VALUE,
435
                configSpecs[index].toString());
455
                configSpecs[index].getIdentifier());
436
        if (defaultPreverifierField != null) {
456
        if (defaultPreverifierField != null) {
437
            setDefaultPreverifier();
457
            setDefaultPreverifier();
438
            defaultPreverifierField.store();
458
            defaultPreverifierField.store();
Lines 454-459 Link Here
454
        return prefNode.getBoolean(
474
        return prefNode.getBoolean(
455
                IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT, false);
475
                IMTJCoreConstants.PREF_PREVERIFY_USE_PROJECT, false);
456
    }
476
    }
477
    
478
        /**
479
         * Add the controls that are for work-in-progress function.
480
         * 
481
         * @param composite
482
         */
483
        private void addTypeOfPreverifier(final Composite composite) {
484
            radioGroupFieldEditor = new RadioGroupFieldEditor (IMTJCoreConstants.PREF_PREVERIFY_TYPE, 
485
            		"Preverifier to use", 1, 
486
            		new String [][] {
487
            		{"Default Preverifier", IMTJCoreConstants.PREF_PREVERIFY_TYPE_DEFAULT},
488
            		{"Emulator Preverifier", IMTJCoreConstants.PREF_PREVERIFY_TYPE_EMULATOR},
489
            		{"Proguard Preverifier", IMTJCoreConstants.PREF_PREVERIFY_TYPE_PROGUARD}
490
            		},
491
            		composite,
492
            		true
493
            );
494
            radioGroupFieldEditor.setPreferenceStore(getPreferenceStore());
495
            radioGroupFieldEditor.load();
496
            radioGroupFieldEditor.fillIntoGrid(composite, 1);
497
                                   
498
            radioGroupFieldEditor.setPropertyChangeListener(new IPropertyChangeListener(){
499
            	public void propertyChange(PropertyChangeEvent event){
500
            		String newValue = (String)event.getNewValue();
501
            		System.out.println(newValue);
502
            		if(!newValue.equals(event.getOldValue())){
503
            			if (newValue.equals("preverify_default")) {
504
            				defaultPreverifierField.setEnabled(true, defaultPreverifierGroup);
505
            			}else if (newValue.equals("preverify_proguard")||newValue.equals("preverify_emulator")) {
506
            				defaultPreverifierField.setEnabled(false, defaultPreverifierGroup);
507
            			}
508
            		}
509
            	}
510
            });
511
            
512
	
513
                       
514
    //        *			"GeneralPage.DoubleClick", resName, 1,
515
    //        *			new String[][] {
516
    //        *				{"Open Browser", "open"},
517
    //        *				{"Expand Tree", "expand"}
518
    //        *			},
519
    //        *          parent
520
            
521
            addField(radioGroupFieldEditor);
522
         }
457
523
458
    /* (non-Javadoc)
524
    /* (non-Javadoc)
459
     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
525
     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
Lines 464-471 Link Here
464
        Composite composite = new Composite(parent, SWT.NONE);
530
        Composite composite = new Composite(parent, SWT.NONE);
465
        composite.setLayout(new GridLayout(1, false));
531
        composite.setLayout(new GridLayout(1, false));
466
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
532
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
467
533
        
468
        addConfigurationControls(composite);
534
        addConfigurationControls(composite);
535
        
536
        addTypeOfPreverifier(composite);
469
537
470
        if (!embeddedInProperties) {
538
        if (!embeddedInProperties) {
471
            addDefaultPreverifierControls(composite);
539
            addDefaultPreverifierControls(composite);
Lines 472-478 Link Here
472
        } else {
540
        } else {
473
            noDefaultAndApplyButton();
541
            noDefaultAndApplyButton();
474
        }
542
        }
475
543
        
476
        setControlsFromPreferences();
544
        setControlsFromPreferences();
477
545
478
        return composite;
546
        return composite;
Lines 477-480 Link Here
477
545
478
        return composite;
546
        return composite;
479
    }
547
    }
548
549
	@Override
550
	protected void createFieldEditors() {
551
		// TODO Auto-generated method stub
552
		
553
	}
554
	
555
	private String getPreverifierType() {
556
		return PreferenceAccessor.instance.getPreverifierType(getProject());
557
558
	}
559
	
560
	public IProject getProject() {
561
        return javaProject.getProject();
562
    }
480
}
563
}

Return to bug 234139