ide.analysis.modernize/src/org/netbeans/modules/ide/analysis/modernize/options/ClangAnalyzerOptions.java
1.1 --- a/ide.analysis.modernize/src/org/netbeans/modules/ide/analysis/modernize/options/ClangAnalyzerOptions.java Sun Jun 25 18:17:37 2017 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,167 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
1.8 - *
1.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
1.10 - * Other names may be trademarks of their respective owners.
1.11 - *
1.12 - * The contents of this file are subject to the terms of either the GNU
1.13 - * General Public License Version 2 only ("GPL") or the Common
1.14 - * Development and Distribution License("CDDL") (collectively, the
1.15 - * "License"). You may not use this file except in compliance with the
1.16 - * License. You can obtain a copy of the License at
1.17 - * http://www.netbeans.org/cddl-gplv2.html
1.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.19 - * specific language governing permissions and limitations under the
1.20 - * License. When distributing the software, include this License Header
1.21 - * Notice in each file and include the License file at
1.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
1.23 - * particular file as subject to the "Classpath" exception as provided
1.24 - * by Oracle in the GPL Version 2 section of the License file that
1.25 - * accompanied this code. If applicable, add the following below the
1.26 - * License Header, with the fields enclosed by brackets [] replaced by
1.27 - * your own identifying information:
1.28 - * "Portions Copyrighted [year] [name of copyright owner]"
1.29 - *
1.30 - * If you wish your version of this file to be governed by only the CDDL
1.31 - * or only the GPL Version 2, indicate your decision by adding
1.32 - * "[Contributor] elects to include this software in this distribution
1.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.34 - * single choice of license, a recipient has the option to distribute
1.35 - * your version of this file under either the CDDL, the GPL Version 2 or
1.36 - * to extend the choice of license to its licensees as provided above.
1.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
1.38 - * Version 2 license, then the option applies only if the new code is
1.39 - * made subject to such option by the copyright holder.
1.40 - *
1.41 - * Contributor(s): Ilia Gromov
1.42 - */
1.43 -
1.44 -package org.netbeans.modules.ide.analysis.modernize.options;
1.45 -
1.46 -import java.io.File;
1.47 -import java.io.IOException;
1.48 -import java.util.Collections;
1.49 -import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
1.50 -import org.netbeans.modules.nativeexecution.api.HostInfo;
1.51 -import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
1.52 -import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
1.53 -import org.openide.modules.InstalledFileLocator;
1.54 -
1.55 -/**
1.56 - *
1.57 - * @author Ilia Gromov
1.58 - */
1.59 -public class ClangAnalyzerOptions {
1.60 -
1.61 - public static final String CLANG_BINARY_NAME = "clang-tidy"; //NOI18N
1.62 - public static final String CLANG_BINARY_PATH = "clang-tidy-path"; //NOI18N
1.63 -
1.64 - private static String findInPaths() {
1.65 - String binaryName = CLANG_BINARY_NAME + "-" + getCodeBase(); //NOI18N
1.66 - String result = HostInfoUtils.searchFile(ExecutionEnvironmentFactory.getLocal(), Collections.<String>emptyList(), binaryName, true); // NOI18N
1.67 - return result;
1.68 - }
1.69 -
1.70 - public static String getClangAnalyzerPath() {
1.71 - String result = AnalyzerPreferences.getPreferences().get(CLANG_BINARY_PATH, ""); //NOI18N
1.72 - String oldValue = result;
1.73 - if (result.isEmpty()) {
1.74 - String toolPath = System.getProperty("devstudio.clangtidy.path"); //NOI18N
1.75 - if (toolPath != null) {
1.76 - result = toolPath;
1.77 - }
1.78 - }
1.79 - if (result.isEmpty()) {
1.80 - final String codeBase = getCodeBase();
1.81 - String relativePath = String.format("%s/%s-%s", CLANG_BINARY_NAME, CLANG_BINARY_NAME, codeBase); //NOI18N
1.82 - File toolFile = InstalledFileLocator.getDefault().locate(relativePath, codeBase, false);
1.83 - if (toolFile != null && toolFile.exists()) {
1.84 - result = toolFile.getAbsolutePath();
1.85 - }
1.86 - }
1.87 - if (result.isEmpty()) {
1.88 - String toolPath = findInPaths();
1.89 - if (toolPath != null) {
1.90 - result = toolPath;
1.91 - }
1.92 - }
1.93 - if (result.isEmpty()) {
1.94 - return null;
1.95 - } else {
1.96 - if (!oldValue.equals(result)) {
1.97 - AnalyzerPreferences.getPreferences().put(CLANG_BINARY_PATH, result);
1.98 - }
1.99 - }
1.100 - return result;
1.101 - }
1.102 -
1.103 - public static String getMissingModuleName() {
1.104 - return "com.oracle.tools.analysis.clangtidy." + getCodeBase(); //NOI18N
1.105 - }
1.106 -
1.107 - public static String getCodeBase() {
1.108 - HostInfo hostInfo = null;
1.109 - try {
1.110 - hostInfo = HostInfoUtils.getHostInfo(ExecutionEnvironmentFactory.getLocal());
1.111 - } catch (IOException ex) {
1.112 - ex.printStackTrace(System.err);
1.113 - } catch (ConnectionManager.CancellationException ex) {
1.114 - ex.printStackTrace(System.err);
1.115 - }
1.116 - String module = null;
1.117 - if (hostInfo != null) {
1.118 - switch (hostInfo.getOS().getFamily()) {
1.119 - case SUNOS:
1.120 - switch (hostInfo.getCpuFamily()) {
1.121 - case X86:
1.122 - switch (hostInfo.getOS().getBitness()) {
1.123 - case _32:
1.124 - module = "SunOS_x86"; // NOI18N
1.125 - break;
1.126 - case _64:
1.127 - module = "SunOS_x86_64"; // NOI18N
1.128 - break;
1.129 - }
1.130 - break;
1.131 - case SPARC:
1.132 - module = "SunOS_sparc"; // NOI18N
1.133 - break;
1.134 - }
1.135 - break;
1.136 - case LINUX:
1.137 - switch (hostInfo.getOS().getBitness()) {
1.138 - case _32:
1.139 - module = "Linux_x86"; // NOI18N
1.140 - break;
1.141 - case _64:
1.142 - module = "Linux_x86_64"; // NOI18N
1.143 - break;
1.144 - }
1.145 - break;
1.146 - case WINDOWS:
1.147 - switch (hostInfo.getOS().getBitness()) {
1.148 - case _32:
1.149 - module = "Windows_x86"; // NOI18N
1.150 - break;
1.151 - case _64:
1.152 - module = "Windows_x86_64"; // NOI18N
1.153 - break;
1.154 - }
1.155 - break;
1.156 - case MACOSX:
1.157 - switch (hostInfo.getOS().getBitness()) {
1.158 - case _32:
1.159 - module = "MacOSX_x86"; // NOI18N
1.160 - break;
1.161 - case _64:
1.162 - module = "MacOSX_x86_64"; // NOI18N
1.163 - break;
1.164 - }
1.165 - break;
1.166 - }
1.167 - }
1.168 - return module;
1.169 - }
1.170 -}