001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.java.api; 021 022import org.apache.commons.lang.StringUtils; 023import org.sonar.api.resources.Project; 024 025/** 026 * @since 2.6 027 * @deprecated in 4.2. See API provided by Java plugins. 028 */ 029@Deprecated 030public final class JavaUtils { 031 032 public static final String PACKAGE_SEPARATOR = "."; 033 public static final String DEFAULT_PACKAGE = "[default]"; 034 035 /** 036 * All sensors executed after this barrier are sure that all Java resources are indexed. 037 */ 038 public static final String BARRIER_BEFORE_SQUID = "BEFORE_SQUID"; 039 040 /** 041 * Sensors executed before this barrier must not rely on index. No Java resources are indexed. 042 * Value is 'squid' in order to be backward-compatible with Sensor.FLAG_SQUID_ANALYSIS. 043 */ 044 public static final String BARRIER_AFTER_SQUID = "squid"; 045 046 /** 047 * To determine value of this property use {@link #getSourceVersion(Project)}. 048 */ 049 public static final String JAVA_SOURCE_PROPERTY = "sonar.java.source"; 050 051 /** 052 * Default value for property {@link #JAVA_SOURCE_PROPERTY}. 053 */ 054 public static final String JAVA_SOURCE_DEFAULT_VALUE = "1.5"; 055 056 /** 057 * To determine value of this property use {@link #getTargetVersion(Project)}. 058 */ 059 public static final String JAVA_TARGET_PROPERTY = "sonar.java.target"; 060 061 /** 062 * Default value for property {@link #JAVA_TARGET_PROPERTY}. 063 */ 064 public static final String JAVA_TARGET_DEFAULT_VALUE = "1.5"; 065 066 private JavaUtils() { 067 // only static methods 068 } 069 070 public static String abbreviatePackage(String packageName) { 071 String[] parts = StringUtils.split(packageName, PACKAGE_SEPARATOR); 072 StringBuilder sb = new StringBuilder(); 073 if (parts.length >= 1) { 074 sb.append(parts[0]); 075 } 076 for (int index = 1; index < parts.length; index++) { 077 sb.append(PACKAGE_SEPARATOR).append(parts[index].charAt(0)); 078 } 079 return sb.toString(); 080 } 081 082 public static String getSourceVersion(Project project) { 083 String version = project.getConfiguration() != null ? project.getConfiguration().getString(JAVA_SOURCE_PROPERTY) : null; 084 return StringUtils.isNotBlank(version) ? version : JAVA_SOURCE_DEFAULT_VALUE; 085 } 086 087 public static String getTargetVersion(Project project) { 088 String version = project.getConfiguration() != null ? project.getConfiguration().getString(JAVA_TARGET_PROPERTY) : null; 089 return StringUtils.isNotBlank(version) ? version : JAVA_TARGET_DEFAULT_VALUE; 090 } 091}