Example usage for org.eclipse.jface.preference IPreferenceStore getString

List of usage examples for org.eclipse.jface.preference IPreferenceStore getString

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore getString.

Prototype

String getString(String name);

Source Link

Document

Returns the current value of the string-valued preference with the given name.

Usage

From source file:com.amazonaws.eclipse.dynamodb.testtool.TestToolManager.java

License:Apache License

/**
 * Get the path to the root install directory as configured in the test
 * tool preference page./*from   ww  w  . ja  v  a2s .  c o m*/
 *
 * @return The path to the root install directory.
 * @throws IOException on error.
 */
private static File getInstallDirectory() throws IOException {
    IPreferenceStore preferences = DynamoDBPlugin.getDefault().getPreferenceStore();

    String directory = preferences.getString(TestToolPreferencePage.DOWNLOAD_DIRECTORY_PREFERENCE_NAME);

    File installDir = new File(directory);

    if (!installDir.exists()) {
        if (!installDir.mkdirs()) {
            throw new IOException("Could not create install directory: " + installDir.getAbsolutePath());
        }
    } else {
        if (!installDir.isDirectory()) {
            throw new IOException(
                    "Configured install directory is " + "not a directory: " + installDir.getAbsolutePath());
        }
    }

    return installDir;
}

From source file:com.amazonaws.eclipse.ec2.PlatformUtils.java

License:Apache License

/**
 * Opens a shell to the specified host using a platform specific terminal
 * window./* w  ww  .java  2  s  . c  o m*/
 * 
 * @param user
 *            The user to connect to the remote host as.
 * @param host
 *            The remote host to connect to.
 * @param identityFile
 *            The file containing the identity file for the connection.
 * @throws IOException
 *             If any problems are encountered opening the remote shell.
 */
public void openShellToRemoteHost(String user, String host, String identityFile)
        throws IOException, InterruptedException, URISyntaxException {

    IPreferenceStore preferenceStore = Ec2Plugin.getDefault().getPreferenceStore();

    String sshOptions = preferenceStore.getString(PreferenceConstants.P_SSH_OPTIONS);
    String sshCommand = preferenceStore.getString(PreferenceConstants.P_SSH_CLIENT);
    sshCommand += " " + sshOptions + " -i " + identityFile + " " + user + "@" + host;

    if (isMac()) {
        URL locationUrl = FileLocator.find(Ec2Plugin.getDefault().getBundle(), new Path("/"), null);
        URL fileUrl = FileLocator.toFileURL(locationUrl);
        executeAsynchronousCommand(new String[] { "osascript",
                fileUrl.getFile() + "scripts/openMacTerminalShell.scpt", sshCommand });
    } else if (isLinux()) {
        String terminalCommand = preferenceStore.getString(PreferenceConstants.P_TERMINAL_EXECUTABLE);

        executeAsynchronousCommand(new String[] { terminalCommand, "-e", sshCommand });
    } else if (isWindows()) {
        openRemoteShellFromWindows(user, host, identityFile);
    } else {
        String osName = System.getProperty("os.name");

        Status status = new Status(IStatus.ERROR, Ec2Plugin.PLUGIN_ID,
                "Unable to determine what platform '" + osName + "' is.");
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
}

From source file:com.android.ddms.DebugPortProvider.java

License:Apache License

/**
 * Create the map member from the values contained in the Preference Store.
 */// w w w .j a  v a  2 s  . co m
private void computePortList() {
    mMap = new HashMap<String, Map<String, Integer>>();

    // get the prefs store
    IPreferenceStore store = PrefsDialog.getStore();
    String value = store.getString(PREFS_STATIC_PORT_LIST);

    if (value != null && value.length() > 0) {
        // format is
        // port1|port2|port3|...
        // where port# is
        // appPackageName:appPortNumber:device-serial-number
        String[] portSegments = value.split("\\|"); //$NON-NLS-1$
        for (String seg : portSegments) {
            String[] entry = seg.split(":"); //$NON-NLS-1$

            // backward compatibility support. if we have only 2 entry, we default
            // to the first emulator.
            String deviceName = null;
            if (entry.length == 3) {
                deviceName = entry[2];
            } else {
                deviceName = IDevice.FIRST_EMULATOR_SN;
            }

            // get the device map
            Map<String, Integer> deviceMap = mMap.get(deviceName);
            if (deviceMap == null) {
                deviceMap = new HashMap<String, Integer>();
                mMap.put(deviceName, deviceMap);
            }

            deviceMap.put(entry[0], Integer.valueOf(entry[1]));
        }
    }
}

From source file:com.android.ddmuilib.log.event.EventLogPanel.java

License:Apache License

/**
 * Loads the {@link EventDisplay}s from the preference store.
 */// ww  w  .  j  ava 2  s .  c  om
private void loadEventDisplays() {
    IPreferenceStore store = DdmUiPreferences.getStore();
    String storage = store.getString(PREFS_EVENT_DISPLAY);

    if (storage.length() > 0) {
        String[] values = storage.split(Pattern.quote(EVENT_DISPLAY_STORAGE_SEPARATOR));

        for (String value : values) {
            EventDisplay eventDisplay = EventDisplay.load(value);
            if (eventDisplay != null) {
                mEventDisplays.add(eventDisplay);
            }
        }
    }
}

From source file:com.android.ide.eclipse.adt.build.ApkBuilder.java

License:Open Source License

/**
 * Makes the final package. Package the dex files, the temporary resource file into the final
 * package file./*  www .  ja  va  2 s . c o m*/
 * @param intermediateApk The path to the temporary resource file.
 * @param dex The path to the dex file.
 * @param output The path to the final package file to create.
 * @param javaProject
 * @param referencedJavaProjects
 * @return true if success, false otherwise.
 */
private boolean finalPackage(String intermediateApk, String dex, String output, final IJavaProject javaProject,
        IJavaProject[] referencedJavaProjects) {
    FileOutputStream fos = null;
    try {
        IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
        String osKeyPath = store.getString(AdtPlugin.PREFS_CUSTOM_DEBUG_KEYSTORE);
        if (osKeyPath == null || new File(osKeyPath).exists() == false) {
            osKeyPath = DebugKeyProvider.getDefaultKeyStoreOsPath();
            AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                    Messages.ApkBuilder_Using_Default_Key);
        } else {
            AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                    String.format(Messages.ApkBuilder_Using_s_To_Sign, osKeyPath));
        }

        // TODO: get the store type from somewhere else.
        DebugKeyProvider provider = new DebugKeyProvider(osKeyPath, null /* storeType */, new IKeyGenOutput() {
            public void err(String message) {
                AdtPlugin.printErrorToConsole(javaProject.getProject(),
                        Messages.ApkBuilder_Signing_Key_Creation_s + message);
            }

            public void out(String message) {
                AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, javaProject.getProject(),
                        Messages.ApkBuilder_Signing_Key_Creation_s + message);
            }
        });
        PrivateKey key = provider.getDebugKey();
        X509Certificate certificate = (X509Certificate) provider.getCertificate();

        if (key == null) {
            String msg = String.format(Messages.Final_Archive_Error_s, Messages.ApkBuilder_Unable_To_Gey_Key);
            AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
            markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
            return false;
        }

        // compare the certificate expiration date
        if (certificate != null && certificate.getNotAfter().compareTo(new Date()) < 0) {
            // TODO, regenerate a new one.
            String msg = String.format(Messages.Final_Archive_Error_s,
                    String.format(Messages.ApkBuilder_Certificate_Expired_on_s,
                            DateFormat.getInstance().format(certificate.getNotAfter())));
            AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
            markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
            return false;
        }

        // create the jar builder.
        fos = new FileOutputStream(output);
        SignedJarBuilder builder = new SignedJarBuilder(fos, key, certificate);

        // add the intermediate file containing the compiled resources.
        AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                String.format(Messages.ApkBuilder_Packaging_s, intermediateApk));
        FileInputStream fis = new FileInputStream(intermediateApk);
        try {
            builder.writeZip(fis, null /* filter */);
        } finally {
            fis.close();
        }

        // Now we add the new file to the zip archive for the classes.dex file.
        AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                String.format(Messages.ApkBuilder_Packaging_s, AndroidConstants.FN_CLASSES_DEX));
        File entryFile = new File(dex);
        builder.writeFile(entryFile, AndroidConstants.FN_CLASSES_DEX);

        // Now we write the standard resources from the project and the referenced projects.
        writeStandardResources(builder, javaProject, referencedJavaProjects);

        // Now we write the standard resources from the external libraries
        for (String libraryOsPath : getExternalJars()) {
            AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                    String.format(Messages.ApkBuilder_Packaging_s, libraryOsPath));
            try {
                fis = new FileInputStream(libraryOsPath);
                builder.writeZip(fis, mJavaResourcesFilter);
            } finally {
                fis.close();
            }
        }

        // now write the native libraries.
        // First look if the lib folder is there.
        IResource libFolder = javaProject.getProject().findMember(SdkConstants.FD_NATIVE_LIBS);
        if (libFolder != null && libFolder.exists() && libFolder.getType() == IResource.FOLDER) {
            // look inside and put .so in lib/* by keeping the relative folder path.
            writeNativeLibraries(libFolder.getFullPath().segmentCount(), builder, libFolder);
        }

        // close the jar file and write the manifest and sign it.
        builder.close();
    } catch (GeneralSecurityException e1) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e1.getMessage());
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } catch (IOException e1) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e1.getMessage());
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } catch (KeytoolException e) {
        String eMessage = e.getMessage();

        // mark the project with the standard message
        String msg = String.format(Messages.Final_Archive_Error_s, eMessage);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);

        // output more info in the console
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg,
                String.format(Messages.ApkBuilder_JAVA_HOME_is_s, e.getJavaHome()),
                Messages.ApkBuilder_Update_or_Execute_manually_s, e.getCommandLine());
    } catch (AndroidLocationException e) {
        String eMessage = e.getMessage();

        // mark the project with the standard message
        String msg = String.format(Messages.Final_Archive_Error_s, eMessage);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);

        // and also output it in the console
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
    } catch (CoreException e) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e.getMessage());
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                // pass.
            }
        }
    }

    return true;
}

From source file:com.android.ide.eclipse.adt.internal.build.ApkBuilder.java

License:Open Source License

/**
 * Makes the final package. Package the dex files, the temporary resource file into the final
 * package file.//from   w  ww  .  ja  v a 2s.  c o  m
 * @param intermediateApk The path to the temporary resource file.
 * @param dex The path to the dex file.
 * @param output The path to the final package file to create.
 * @param javaProject
 * @param referencedJavaProjects
 * @return true if success, false otherwise.
 */
private boolean finalPackage(String intermediateApk, String dex, String output, final IJavaProject javaProject,
        IJavaProject[] referencedJavaProjects) {
    FileOutputStream fos = null;
    try {
        IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
        String osKeyPath = store.getString(AdtPlugin.PREFS_CUSTOM_DEBUG_KEYSTORE);
        if (osKeyPath == null || new File(osKeyPath).exists() == false) {
            osKeyPath = DebugKeyProvider.getDefaultKeyStoreOsPath();
            AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                    Messages.ApkBuilder_Using_Default_Key);
        } else {
            AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                    String.format(Messages.ApkBuilder_Using_s_To_Sign, osKeyPath));
        }

        // TODO: get the store type from somewhere else.
        DebugKeyProvider provider = new DebugKeyProvider(osKeyPath, null /* storeType */, new IKeyGenOutput() {
            public void err(String message) {
                AdtPlugin.printErrorToConsole(javaProject.getProject(),
                        Messages.ApkBuilder_Signing_Key_Creation_s + message);
            }

            public void out(String message) {
                AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, javaProject.getProject(),
                        Messages.ApkBuilder_Signing_Key_Creation_s + message);
            }
        });
        PrivateKey key = provider.getDebugKey();
        X509Certificate certificate = (X509Certificate) provider.getCertificate();

        if (key == null) {
            String msg = String.format(Messages.Final_Archive_Error_s, Messages.ApkBuilder_Unable_To_Gey_Key);
            AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
            markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
            return false;
        }

        // compare the certificate expiration date
        if (certificate != null && certificate.getNotAfter().compareTo(new Date()) < 0) {
            // TODO, regenerate a new one.
            String msg = String.format(Messages.Final_Archive_Error_s,
                    String.format(Messages.ApkBuilder_Certificate_Expired_on_s,
                            DateFormat.getInstance().format(certificate.getNotAfter())));
            AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
            markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
            return false;
        }

        // create the jar builder.
        fos = new FileOutputStream(output);
        SignedJarBuilder builder = new SignedJarBuilder(fos, key, certificate);

        // add the intermediate file containing the compiled resources.
        AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                String.format(Messages.ApkBuilder_Packaging_s, intermediateApk));
        FileInputStream fis = new FileInputStream(intermediateApk);
        try {
            builder.writeZip(fis, null /* filter */);
        } finally {
            fis.close();
        }

        // Now we add the new file to the zip archive for the classes.dex file.
        AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                String.format(Messages.ApkBuilder_Packaging_s, AndroidConstants.FN_CLASSES_DEX));
        File entryFile = new File(dex);
        builder.writeFile(entryFile, AndroidConstants.FN_CLASSES_DEX);

        // Now we write the standard resources from the project and the referenced projects.
        writeStandardResources(builder, javaProject, referencedJavaProjects);

        // Now we write the standard resources from the external libraries
        for (String libraryOsPath : getExternalJars()) {
            AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
                    String.format(Messages.ApkBuilder_Packaging_s, libraryOsPath));
            try {
                fis = new FileInputStream(libraryOsPath);
                builder.writeZip(fis, mJavaResourcesFilter);
            } finally {
                fis.close();
            }
        }

        // now write the native libraries.
        // First look if the lib folder is there.
        IResource libFolder = javaProject.getProject().findMember(SdkConstants.FD_NATIVE_LIBS);
        if (libFolder != null && libFolder.exists() && libFolder.getType() == IResource.FOLDER) {
            // look inside and put .so in lib/* by keeping the relative folder path.
            writeNativeLibraries(libFolder.getFullPath().segmentCount(), builder, libFolder);
        }

        // close the jar file and write the manifest and sign it.
        builder.close();
    } catch (GeneralSecurityException e1) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e1.getMessage());
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } catch (IOException e1) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e1.getMessage());
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } catch (KeytoolException e) {
        String eMessage = e.getMessage();

        // mark the project with the standard message
        String msg = String.format(Messages.Final_Archive_Error_s, eMessage);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);

        // output more info in the console
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg,
                String.format(Messages.ApkBuilder_JAVA_HOME_is_s, e.getJavaHome()),
                Messages.ApkBuilder_Update_or_Execute_manually_s, e.getCommandLine());
    } catch (AndroidLocationException e) {
        String eMessage = e.getMessage();

        // mark the project with the standard message
        String msg = String.format(Messages.Final_Archive_Error_s, eMessage);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);

        // and also output it in the console
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
    } catch (CoreException e) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e.getMessage());
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } catch (Exception e) {
        // try to catch other exception to actually display an error. This will be useful
        // if we get an NPE or something so that we can at least notify the user that something
        // went wrong (otherwise the build appears to succeed but the zip archive is not closed
        // and therefore invalid.
        String msg = e.getMessage();
        if (msg == null) {
            msg = e.getClass().getCanonicalName();
        }

        msg = String.format("Unknown error: %1$s", msg);
        AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
        markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
        return false;
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                // pass.
            }
        }
    }

    return true;
}

From source file:com.android.ide.eclipse.adt.internal.build.BuildHelper.java

License:Open Source License

/**
 * Makes a final package signed with the debug key.
 *
 * Packages the dex files, the temporary resource file into the final package file.
 *
 * Whether the package is a debug package is controlled with the <var>debugMode</var> parameter
 * in {@link #PostCompilerHelper(IProject, PrintStream, PrintStream, boolean, boolean)}
 *
 * @param intermediateApk The path to the temporary resource file.
 * @param dex The path to the dex file./*  www .  ja  v a 2 s.  co  m*/
 * @param output The path to the final package file to create.
 * @param libProjects an optional list of library projects (can be null)
 * @return true if success, false otherwise.
 * @throws ApkCreationException
 * @throws AndroidLocationException
 * @throws KeytoolException
 * @throws NativeLibInJarException
 * @throws CoreException
 * @throws DuplicateFileException
 */
public void finalDebugPackage(String intermediateApk, String dex, String output, List<IProject> libProjects,
        ResourceMarker resMarker) throws ApkCreationException, KeytoolException, AndroidLocationException,
        NativeLibInJarException, DuplicateFileException, CoreException {

    AdtPlugin adt = AdtPlugin.getDefault();
    if (adt == null) {
        return;
    }

    // get the debug keystore to use.
    IPreferenceStore store = adt.getPreferenceStore();
    String keystoreOsPath = store.getString(AdtPrefs.PREFS_CUSTOM_DEBUG_KEYSTORE);
    if (keystoreOsPath == null || new File(keystoreOsPath).isFile() == false) {
        keystoreOsPath = DebugKeyProvider.getDefaultKeyStoreOsPath();
        AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, mProject, Messages.ApkBuilder_Using_Default_Key);
    } else {
        AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, mProject,
                String.format(Messages.ApkBuilder_Using_s_To_Sign, keystoreOsPath));
    }

    // from the keystore, get the signing info
    SigningInfo info = ApkBuilder.getDebugKey(keystoreOsPath, mVerbose ? mOutStream : null);

    finalPackage(intermediateApk, dex, output, libProjects, info != null ? info.key : null,
            info != null ? info.certificate : null, resMarker);
}

From source file:com.android.ide.eclipse.adt.internal.build.PostCompilerHelper.java

License:Open Source License

/**
 * Makes the final package. Package the dex files, the temporary resource file into the final
 * package file./*w  w w .  j av a 2 s . c  o m*/
 * @param intermediateApk The path to the temporary resource file.
 * @param dex The path to the dex file.
 * @param output The path to the final package file to create.
 * @param debugSign whether the apk must be signed with the debug key.
 * @param javaProject the java project being compiled
 * @param libProjects an optional list of library projects (can be null)
 * @param referencedJavaProjects referenced projects.
 * @param abiFilter an optional filter. If not null, then only the matching ABI is included in
 * the final archive
 * @param debuggable whether the project manifest has debuggable==true. If true, any gdbserver
 * executables will be packaged with the native libraries.
 * @return true if success, false otherwise.
 */
public boolean finalPackage(String intermediateApk, String dex, String output, boolean debugSign,
        final IJavaProject javaProject, IProject[] libProjects, IJavaProject[] referencedJavaProjects,
        String abiFilter, boolean debuggable) {

    IProject project = javaProject.getProject();

    String keystoreOsPath = null;
    if (debugSign) {
        IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
        keystoreOsPath = store.getString(AdtPrefs.PREFS_CUSTOM_DEBUG_KEYSTORE);
        if (keystoreOsPath == null || new File(keystoreOsPath).isFile() == false) {
            try {
                keystoreOsPath = DebugKeyProvider.getDefaultKeyStoreOsPath();
                AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, mProject,
                        Messages.ApkBuilder_Using_Default_Key);
            } catch (KeytoolException e) {
                String eMessage = e.getMessage();

                // mark the project with the standard message
                String msg = String.format(Messages.Final_Archive_Error_s, eMessage);
                BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg,
                        IMarker.SEVERITY_ERROR);

                // output more info in the console
                AdtPlugin.printErrorToConsole(mProject, msg,
                        String.format(Messages.ApkBuilder_JAVA_HOME_is_s, e.getJavaHome()),
                        Messages.ApkBuilder_Update_or_Execute_manually_s, e.getCommandLine());

                return false;
            } catch (AndroidLocationException e) {
                String eMessage = e.getMessage();

                // mark the project with the standard message
                String msg = String.format(Messages.Final_Archive_Error_s, eMessage);
                BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg,
                        IMarker.SEVERITY_ERROR);

                return false;
            }
        } else {
            AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, mProject,
                    String.format(Messages.ApkBuilder_Using_s_To_Sign, keystoreOsPath));
        }
    }

    try {
        ApkBuilder apkBuilder = new ApkBuilder(output, intermediateApk, dex, keystoreOsPath,
                AdtPrefs.getPrefs().getBuildVerbosity() == BuildVerbosity.VERBOSE
                        ? AdtPlugin.getOutPrintStream(project, null)
                        : null);
        apkBuilder.setDebugMode(debuggable);

        // Now we write the standard resources from the project and the referenced projects.
        writeStandardResources(apkBuilder, javaProject, referencedJavaProjects);

        // Now we write the standard resources from the external jars
        for (String libraryOsPath : getExternalJars()) {
            JarStatus status = apkBuilder.addResourcesFromJar(new File(libraryOsPath));

            // check if we found native libraries in the external library. This
            // constitutes an error or warning depending on if they are in lib/
            if (status.getNativeLibs().size() > 0) {
                String libName = new File(libraryOsPath).getName();
                String msg = String.format(
                        "Native libraries detected in '%1$s'. See console for more information.", libName);

                BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg,
                        status.hasNativeLibsConflicts()
                                || AdtPrefs.getPrefs().getBuildForceErrorOnNativeLibInJar()
                                        ? IMarker.SEVERITY_ERROR
                                        : IMarker.SEVERITY_WARNING);

                ArrayList<String> consoleMsgs = new ArrayList<String>();
                consoleMsgs.add(String.format(
                        "The library '%1$s' contains native libraries that will not run on the device.",
                        libName));
                if (status.hasNativeLibsConflicts()) {
                    consoleMsgs.add(
                            "Additionally some of those libraries will interfer with the installation of the application because of their location in lib/");
                    consoleMsgs.add("lib/ is reserved for NDK libraries.");
                }
                consoleMsgs.add("The following libraries were found:");
                for (String lib : status.getNativeLibs()) {
                    consoleMsgs.add(" - " + lib);
                }
                AdtPlugin.printErrorToConsole(mProject, consoleMsgs.toArray());

                return false;
            }
        }

        // now write the native libraries.
        // First look if the lib folder is there.
        IResource libFolder = mProject.findMember(SdkConstants.FD_NATIVE_LIBS);
        if (libFolder != null && libFolder.exists() && libFolder.getType() == IResource.FOLDER) {
            // get a File for the folder.
            apkBuilder.addNativeLibraries(libFolder.getLocation().toFile(), abiFilter);
        }

        // write the native libraries for the library projects.
        if (libProjects != null) {
            for (IProject lib : libProjects) {
                libFolder = lib.findMember(SdkConstants.FD_NATIVE_LIBS);
                if (libFolder != null && libFolder.exists() && libFolder.getType() == IResource.FOLDER) {
                    apkBuilder.addNativeLibraries(libFolder.getLocation().toFile(), abiFilter);
                }
            }
        }

        // seal the APK.
        apkBuilder.sealApk();
        return true;
    } catch (CoreException e) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e.getMessage());
        AdtPlugin.printErrorToConsole(mProject, msg);
        BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg,
                IMarker.SEVERITY_ERROR);
    } catch (ApkCreationException e) {
        // mark project and return
        String msg = String.format(Messages.Final_Archive_Error_s, e.getMessage());
        AdtPlugin.printErrorToConsole(mProject, msg);
        BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg,
                IMarker.SEVERITY_ERROR);
    } catch (DuplicateFileException e) {
        String msg1 = String.format("Found duplicate file for APK: %1$s\nOrigin 1: %2$s\nOrigin 2: %3$s",
                e.getArchivePath(), e.getFile1(), e.getFile2());
        String msg2 = String.format(Messages.Final_Archive_Error_s, msg1);
        AdtPlugin.printErrorToConsole(mProject, msg2);
        BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg2,
                IMarker.SEVERITY_ERROR);
    } catch (SealedApkException e) {
        // this won't happen as we control when the apk is sealed.
    } catch (Exception e) {
        // try to catch other exception to actually display an error. This will be useful
        // if we get an NPE or something so that we can at least notify the user that something
        // went wrong (otherwise the build appears to succeed but the zip archive is not closed
        // and therefore invalid.
        String msg = e.getMessage();
        if (msg == null) {
            msg = e.getClass().getCanonicalName();
        }

        msg = String.format("Unknown error: %1$s", msg);
        AdtPlugin.printErrorToConsole(mProject, msg);
        BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, msg,
                IMarker.SEVERITY_ERROR);
    }

    return false;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.properties.XmlPropertyEditor.java

License:Open Source License

@Override
protected boolean setEditorText(Property property, String text) throws Exception {
    Object oldValue = property.getValue();
    String old = oldValue != null ? oldValue.toString() : null;

    // If users enters a new id without specifying the @id/@+id prefix, insert it
    boolean isId = isIdProperty(property);
    if (isId && !text.startsWith(PREFIX_RESOURCE_REF)) {
        text = NEW_ID_PREFIX + text;// www.  j  ava  2 s . c  o  m
    }

    // Handle id refactoring: if you change an id, may want to update references too.
    // Ask user.
    if (isId && property instanceof XmlProperty && old != null && !old.isEmpty() && text != null
            && !text.isEmpty() && !text.equals(old)) {
        XmlProperty xmlProperty = (XmlProperty) property;
        IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
        String refactorPref = store.getString(AdtPrefs.PREFS_REFACTOR_IDS);
        boolean performRefactor = false;
        Shell shell = AdtPlugin.getShell();
        if (refactorPref == null || refactorPref.isEmpty()
                || refactorPref.equals(MessageDialogWithToggle.PROMPT)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(shell,
                    "Update References?",
                    "Update all references as well? "
                            + "This will update all XML references and Java R field references.",
                    "Do not show again", false, store, AdtPrefs.PREFS_REFACTOR_IDS);
            switch (dialog.getReturnCode()) {
            case IDialogConstants.CANCEL_ID:
                return false;
            case IDialogConstants.YES_ID:
                performRefactor = true;
                break;
            case IDialogConstants.NO_ID:
                performRefactor = false;
                break;
            }
        } else {
            performRefactor = refactorPref.equals(MessageDialogWithToggle.ALWAYS);
        }
        if (performRefactor) {
            CommonXmlEditor xmlEditor = xmlProperty.getXmlEditor();
            if (xmlEditor != null) {
                IProject project = xmlEditor.getProject();
                if (project != null && shell != null) {
                    RenameResourceWizard.renameResource(shell, project, ResourceType.ID, stripIdPrefix(old),
                            stripIdPrefix(text), false);
                }
            }
        }
    }

    property.setValue(text);

    return true;
}

From source file:com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.java

License:Open Source License

/**
 * Returns an {@link ILaunchConfiguration} for the specified {@link IProject}.
 * @param project the project/* w  w  w  .j a v  a 2  s .  c o m*/
 * @param launchTypeId launch delegate type id
 * @return a new or already existing <code>ILaunchConfiguration</code> or null if there was
 * an error when creating a new one.
 */
public static ILaunchConfiguration getLaunchConfig(IProject project, String launchTypeId) {
    // get the launch manager
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

    // now get the config type for our particular android type.
    ILaunchConfigurationType configType = manager.getLaunchConfigurationType(launchTypeId);

    String name = project.getName();

    // search for an existing launch configuration
    ILaunchConfiguration config = findConfig(manager, configType, name);

    // test if we found one or not
    if (config == null) {
        // Didn't find a matching config, so we make one.
        // It'll be made in the "working copy" object first.
        ILaunchConfigurationWorkingCopy wc = null;

        try {
            // make the working copy object
            wc = configType.newInstance(null, manager.generateLaunchConfigurationName(name));

            // set the project name
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);

            // set the launch mode to default.
            wc.setAttribute(LaunchConfigDelegate.ATTR_LAUNCH_ACTION,
                    LaunchConfigDelegate.DEFAULT_LAUNCH_ACTION);

            // set default target mode
            wc.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
                    LaunchConfigDelegate.DEFAULT_TARGET_MODE.toString());

            // default AVD: None
            wc.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, (String) null);

            // set the default network speed
            wc.setAttribute(LaunchConfigDelegate.ATTR_SPEED, LaunchConfigDelegate.DEFAULT_SPEED);

            // and delay
            wc.setAttribute(LaunchConfigDelegate.ATTR_DELAY, LaunchConfigDelegate.DEFAULT_DELAY);

            // default wipe data mode
            wc.setAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA, LaunchConfigDelegate.DEFAULT_WIPE_DATA);

            // default disable boot animation option
            wc.setAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM, LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM);

            // set default emulator options
            IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
            String emuOptions = store.getString(AdtPrefs.PREFS_EMU_OPTIONS);
            wc.setAttribute(LaunchConfigDelegate.ATTR_COMMANDLINE, emuOptions);

            // map the config and the project
            wc.setMappedResources(getResourcesToMap(project));

            // save the working copy to get the launch config object which we return.
            return wc.doSave();

        } catch (CoreException e) {
            String msg = String.format("Failed to create a Launch config for project '%1$s': %2$s",
                    project.getName(), e.getMessage());
            AdtPlugin.printErrorToConsole(project, msg);

            // no launch!
            return null;
        }
    }

    return config;
}