Skip to content

Commit

Permalink
Metadata Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurabdg committed Aug 10, 2020
1 parent 96726c6 commit 7258760
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*/bin/
*/target/
.idea/
*.iml
*.prefs
.checkstyle
2 changes: 1 addition & 1 deletion net.sf.eclipsecs.checkstyle/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="checkstyle-8.34-all.jar" sourcepath="checkstyle-checkstyle-8.34.zip"/>
<classpathentry exported="true" kind="lib" path="checkstyle-8.35-all.jar" sourcepath="checkstyle-checkstyle-8.34.zip"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion net.sf.eclipsecs.checkstyle/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ Export-Package: .,
com.puppycrawl.tools.checkstyle.utils,
org.apache.commons.beanutils;version="8.34.0"
Bundle-ClassPath: .,
checkstyle-8.34-all.jar
checkstyle-8.35-all.jar
Automatic-Module-Name: net.sf.eclipsecs.checkstyle
2 changes: 1 addition & 1 deletion net.sf.eclipsecs.checkstyle/build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bin.includes = META-INF/,\
.,\
license/,\
checkstyle-8.34-all.jar
checkstyle-8.35-all.jar
jars.compile.order = .
source.. = metadata/
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
</property-metadata>
<property-metadata name="accessModifiers" datatype="SingleSelect" default-value="PUBLIC,PROTECTED,PACKAGE,PRIVATE">
<description>%ParameterName.accessModifiers</description>
<enumeration option-provider="com.puppycrawl.tools.checkstyle.checks.naming.AccessModifier"/>
<enumeration
option-provider="com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption"/>
</property-metadata>
<message-key key="name.invalidPattern"/>
</rule-metadata>
Expand Down
4 changes: 2 additions & 2 deletions net.sf.eclipsecs.checkstyle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>Checkstyle Core Library Plugin</name>

<properties>
<checkstyle.version>8.34</checkstyle.version>
<checkstyle.version>8.35</checkstyle.version>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -87,4 +87,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
2 changes: 2 additions & 0 deletions net.sf.eclipsecs.core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/dom4j-2.1.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/metadata-gen-1.0-SNAPSHOT.jar"/>
<classpathentry exported="true" kind="lib" path="lib/reflections-0.9.10.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
4 changes: 3 additions & 1 deletion net.sf.eclipsecs.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Bundle-SymbolicName: net.sf.eclipsecs.core;singleton:=true
Bundle-Version: 8.34.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .,
lib/dom4j-2.1.3.jar
lib/dom4j-2.1.3.jar,
lib/metadata-gen-1.0-SNAPSHOT.jar,
lib/reflections-0.9.10.jar
Bundle-Activator: net.sf.eclipsecs.core.CheckstylePlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse Checkstyle Project
Expand Down
4 changes: 3 additions & 1 deletion net.sf.eclipsecs.core/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ bin.includes = .,\
plugin.xml,\
schema/,\
core.properties,\
lib/dom4j-2.1.3.jar
lib/dom4j-2.1.3.jar, \
lib/metadata-gen-1.0-SNAPSHOT.jar, \
lib/reflections-0.9.10.jar
source.. = src/

Binary file not shown.
Binary file added net.sf.eclipsecs.core/lib/reflections-0.9.10.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.sf.eclipsecs.core.config.meta;

import java.util.Set;

import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
import com.puppycrawl.tools.checkstyle.PackageObjectFactory;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck;
import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
import com.puppycrawl.tools.checkstyle.utils.TokenUtil;

import net.sf.eclipsecs.core.CheckstylePlugin;

public final class CheckUtil {
private CheckUtil() {
}

public static Object getCheck(String checkName) {
final ClassLoader classLoader = CheckstylePlugin.getDefault()
.getAddonExtensionClassLoader();
try {
final Set<String> packageNames = PackageNamesLoader.getPackageNames(classLoader);
return new PackageObjectFactory(packageNames, classLoader)
.createModule(checkName);
}
catch (CheckstyleException ex) {
throw new IllegalStateException("exception occured during load of " + checkName, ex);
}
}

public static String getAcceptableTokens(String checkName) {
final Object checkResult = getCheck(checkName);
String result = null;
if (AbstractJavadocCheck.class.isAssignableFrom(checkResult.getClass())) {
final AbstractJavadocCheck javadocCheck = (AbstractJavadocCheck) checkResult;
result = getTokenText(true, javadocCheck.getAcceptableJavadocTokens(),
javadocCheck.getRequiredJavadocTokens());
}
else if (AbstractCheck.class.isAssignableFrom(checkResult.getClass())) {
final AbstractCheck check = (AbstractCheck) checkResult;
result = getTokenText(false, check.getAcceptableTokens(),
check.getRequiredTokens());
}
return result;
}

public static String getTokenText(boolean isJavadocCheck, int[] tokens, int... requiredTokens) {
final StringBuilder result = new StringBuilder();
boolean first = true;

for (int token : tokens) {
boolean found = false;

for (int subtraction : requiredTokens) {
if (subtraction == token) {
found = true;
break;
}
}

if (found) {
continue;
}

if (first) {
first = false;
}
else {
result.append(',');
}

if (isJavadocCheck) {
result.append(JavadocUtil.getTokenName(token));
}
else {
result.append(TokenUtil.getTokenName(token));
}
}

return result.toString();
}
}

Loading

0 comments on commit 7258760

Please sign in to comment.