From f0830f0dcfefb721a37c068cfc382cb01d9ba57f Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Thu, 15 Jan 2015 15:23:14 +0100 Subject: [PATCH] Remove classes which are no longer used --- .../plugins/scala/language/ScalaFile.java | 167 ------------------ .../plugins/scala/language/ScalaPackage.java | 91 ---------- 2 files changed, 258 deletions(-) delete mode 100644 src/main/java/org/sonar/plugins/scala/language/ScalaFile.java delete mode 100644 src/main/java/org/sonar/plugins/scala/language/ScalaPackage.java diff --git a/src/main/java/org/sonar/plugins/scala/language/ScalaFile.java b/src/main/java/org/sonar/plugins/scala/language/ScalaFile.java deleted file mode 100644 index 100d948..0000000 --- a/src/main/java/org/sonar/plugins/scala/language/ScalaFile.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Sonar Scala Plugin - * Copyright (C) 2011 - 2014 All contributors - * dev@sonar.codehaus.org - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.scala.language; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.sonar.api.resources.InputFile; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.Scopes; -import org.sonar.api.utils.WildcardPattern; - -/** - * This class implements a Scala source file for Sonar. - * - * @author Felix Müller - * @since 0.1 - */ -public class ScalaFile extends Resource { - - private final boolean isUnitTest; - - private final String filename; - - private final String longName; - - private final ScalaPackage parent; - - public ScalaFile(String packageKey, String className, boolean isUnitTest) { - super(); - this.isUnitTest = isUnitTest; - filename = className.trim(); - - String key; - if (StringUtils.isBlank(packageKey)) { - packageKey = ScalaPackage.DEFAULT_PACKAGE_NAME; - key = new StringBuilder().append(packageKey).append(".").append(this.filename).toString(); - longName = filename; - } else { - packageKey = packageKey.trim(); - key = new StringBuilder().append(packageKey).append(".").append(this.filename).toString(); - longName = key; - } - parent = new ScalaPackage(packageKey); - setKey(key); - } - - @Override - public String getName() { - return filename; - } - - @Override - public String getLongName() { - return longName; - } - - @Override - public String getDescription() { - return null; - } - - @Override - public Language getLanguage() { - return Scala.INSTANCE; - } - - @Override - public String getScope() { - return Scopes.FILE; - } - - @Override - public String getQualifier() { - return isUnitTest ? Qualifiers.UNIT_TEST_FILE : Qualifiers.FILE; - } - - @Override - public ScalaPackage getParent() { - return parent; - } - - @Override - public boolean matchFilePattern(String antPattern) { - final String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, "."); - final WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, "."); - return matcher.match(getKey()); - } - - public boolean isUnitTest() { - return isUnitTest; - } - - /** - * Shortcut for {@link #fromInputFile(InputFile, boolean)} for source files. - */ - public static ScalaFile fromInputFile(InputFile inputFile) { - return ScalaFile.fromInputFile(inputFile, false); - } - - /** - * Creates a {@link ScalaFile} from a file in the source directories. - * - * @param inputFile - * the file object with relative path - * @param isUnitTest - * whether it is a unit test file or a source file - * @return the {@link ScalaFile} created if exists, null otherwise - */ - public static ScalaFile fromInputFile(InputFile inputFile, boolean isUnitTest) { - if (inputFile == null || inputFile.getFile() == null || inputFile.getRelativePath() == null) { - return null; - } - - String packageName = PackageResolver.resolvePackageNameOfFile(inputFile.getFile().getAbsolutePath()); - String className = resolveClassName(inputFile); - - if (isPackageObjectInFirstLevelPackage(packageName, className)) { - String lastFolderName = extractLastFolderName(inputFile); - return new ScalaFile(StringUtils.EMPTY, lastFolderName + "." + className, isUnitTest); - } - - return new ScalaFile(packageName, className, isUnitTest); - } - - private static boolean isPackageObjectInFirstLevelPackage(String packageName, String className) { - return "".equalsIgnoreCase(packageName) && "package".equalsIgnoreCase(className); - } - - private static String extractLastFolderName(InputFile inputFile) { - String absolutePath = inputFile.getFile().getAbsolutePath(); - int lastPathSeparator = absolutePath.lastIndexOf("/"); - return absolutePath.substring(absolutePath.lastIndexOf("/", lastPathSeparator - 1) + 1, lastPathSeparator); - } - - private static String resolveClassName(InputFile inputFile) { - String classname = inputFile.getRelativePath(); - if (inputFile.getRelativePath().indexOf('/') >= 0) { - classname = StringUtils.substringAfterLast(inputFile.getRelativePath(), "/"); - } - return StringUtils.substringBeforeLast(classname, "."); - } - - @Override - public String toString() { - return new ToStringBuilder(this).append("key", getKey()).append("fileName", filename) - .append("isUnitTest", isUnitTest).append("longName", longName).append("parent", parent).toString(); - } -} diff --git a/src/main/java/org/sonar/plugins/scala/language/ScalaPackage.java b/src/main/java/org/sonar/plugins/scala/language/ScalaPackage.java deleted file mode 100644 index 12e14fc..0000000 --- a/src/main/java/org/sonar/plugins/scala/language/ScalaPackage.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Sonar Scala Plugin - * Copyright (C) 2011 - 2014 All contributors - * dev@sonar.codehaus.org - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.scala.language; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.Scopes; -import org.sonar.api.utils.WildcardPattern; - -/** - * This class implements a logical Scala package. - * - * @author Felix Müller - * @since 0.1 - */ -@SuppressWarnings("rawtypes") -public class ScalaPackage extends Resource { - public static final String DEFAULT_PACKAGE_NAME = "[default]"; - - public ScalaPackage(String key) { - super(); - setKey(StringUtils.defaultIfEmpty(StringUtils.trim(key), DEFAULT_PACKAGE_NAME)); - } - - @Override - public String getName() { - return getKey(); - } - - @Override - public String getLongName() { - return null; - } - - @Override - public String getDescription() { - return null; - } - - @Override - public Language getLanguage() { - return Scala.INSTANCE; - } - - @Override - public String getScope() { - return Scopes.DIRECTORY; - } - - @Override - public String getQualifier() { - return Qualifiers.PACKAGE; - } - - @Override - public Resource getParent() { - return null; - } - - @Override - public boolean matchFilePattern(String antPattern) { - String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, "."); - WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, "."); - return matcher.match(getKey()); - } - - @Override - public String toString() { - return new ToStringBuilder(this).append("key", getKey()).toString(); - } -}