/grevecom/src/org/eclipse/conesc/plugin/utils/BinarySelector.java
https://bitbucket.org/muxa/conesc · Java · 89 lines · 61 code · 12 blank · 16 comment · 16 complexity · 31ece5e7278c4704c09dd238998d4b14 MD5 · raw file
- /*******************************************************************************
- * Copyright (c) 2014 Mikhail Afanasov and DeepSe Group.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Mikhail Afanasov - initial API and implementation
- ?*******************************************************************************/
- package org.eclipse.conesc.plugin.utils;
- import java.io.IOException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import java.net.URL;
- import java.util.Collections;
- import org.eclipse.conesc.plugin.ConesCPlugin;
- import org.eclipse.core.runtime.FileLocator;
- import org.eclipse.core.runtime.Path;
- import org.eclipse.core.runtime.Platform;
- import org.osgi.framework.Bundle;
- public class BinarySelector {
-
- public static final String MACOS = "Mac";
- public static final String LINUX = "Linux";
- public static final String LINUX32 = "Linux32";
- public static final String LINUX64 = "Linux64";
- public static final String WINDOWS = "Windows";
- public static final String WINDOWS32 = "Windows32";
- public static final String WINDOWS64 = "Windows64";
-
- public static String osCheck() {
- String os = System.getProperty("os.name");
- if (os.startsWith(MACOS)) return MACOS;
- if (os.startsWith(LINUX)) {
- String arch = System.getProperty("os.arch");
- String realArch = arch.endsWith("64") ? "64" : "32";
- return LINUX+realArch;
- }
- if (os.startsWith(WINDOWS)) {
- String arch = System.getenv("PROCESSOR_ARCHITECTURE");
- String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");
- String realArch = arch.endsWith("64")
- || wow64Arch != null && wow64Arch.endsWith("64")
- ? "64" : "32";
- return WINDOWS+realArch;
- }
- return os;
- }
-
- public static String getNuSMVBin() throws IOException {
- Bundle bundle = Platform.getBundle("org.eclipse.conesc.plugin");
- Path path = null;
- String result = "";
- if (bundle == null)
- result = BinarySelector.class.getProtectionDomain().getCodeSource().getLocation().getPath();
- if (osCheck().equals(MACOS)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_mac/NuSMV");
- if (osCheck().equals(LINUX32)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_linux/NuSMV");
- if (osCheck().equals(LINUX64)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_linux_64/NuSMV");
- if (osCheck().equals(WINDOWS64)) path = new Path("/NuSMV-2.5.4-linux-mac/bin_win_64/NuSMV.exe");
- if (path == null) throw new IOException("I do not have NuSMV binary for your "+osCheck()+" system.");
- if (bundle == null)
- return result+"../"+path.toString();
-
- String uri = "";
- try{
- uri = ConesCPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
- uri = uri.substring(0, uri.lastIndexOf(Path.SEPARATOR))+path.toString();
- System.out.println("URI!!! "+uri);
- } catch (URISyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- //URL urlToFoo = FileLocator.toFileURL(new URL("platform:/plugin/org.eclipse.conesc.plugin/"+path.toString()));
-
- //URL relative_path = FileLocator.find(bundle,path,Collections.EMPTY_MAP);
- //URL absolute_path = FileLocator.resolve(relative_path);
- //System.err.println("relative path "+relative_path.toString());
- //System.err.println("absolute path "+absolute_path.toString());
- return uri;//absolute_path.getPath();
- }
- }