/* * Sonar Drools Plugin * Copyright (C) 2011 Jérémie Lagarde * dev@sonar.codehaus.org * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.sonar.plugins.drools.resources; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.resources.Language; import org.sonar.api.resources.Resource; import org.sonar.api.utils.WildcardPattern; import org.sonar.plugins.drools.language.Drools; /** * Drools package as sonar resource. * * @author Jeremie Lagarde * @since 0.1 */ public class DroolsPackage extends Resource<Resource> { public static final String DEFAULT_PACKAGE_NAME = "[default]"; public DroolsPackage(String key) { super(); setKey(StringUtils.defaultIfEmpty(StringUtils.trim(key), DEFAULT_PACKAGE_NAME)); } public boolean matchFilePattern(String antPattern) { String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, "."); WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, "."); return matcher.match(getKey()); } public String getDescription() { return null; } public String getScope() { return Resource.SCOPE_SPACE; } public String getQualifier() { return Resource.QUALIFIER_PACKAGE; } public String getName() { return getKey(); } public Resource<?> getParent() { return null; } public String getLongName() { return null; } public Language getLanguage() { return Drools.INSTANCE; } @Override public String toString() { return new ToStringBuilder(this) .append("key", getKey()) .toString(); } }