Skip to content

Commit

Permalink
Issue #19: Module Component
Browse files Browse the repository at this point in the history
  • Loading branch information
Luolc committed Jun 23, 2017
1 parent d5b776e commit 6c42f41
Show file tree
Hide file tree
Showing 16 changed files with 3,191 additions and 16 deletions.
14 changes: 14 additions & 0 deletions config/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
<allow pkg="java.io"/>
<allow pkg="java.util"/>
<allow pkg="com.github.checkstyle.regression.data"/>
<allow pkg="com.github.checkstyle.regression.util"/>
<allow pkg="org.immutables"/>

<subpackage name="git">
<allow pkg="org.eclipse.jgit"/>
</subpackage>

<subpackage name="module">
<allow pkg="com.google.gson"/>
<!-- Keep this until we don't need hardcode ModuleInfo map. -->
<allow class="java.nio.charset.Charset"/>
</subpackage>

<subpackage name="util">
<allow pkg="com.google.gson"/>
<allow class="com.sun.tools.javac.util.ServiceLoader"/>
</subpackage>
</import-control>
10 changes: 9 additions & 1 deletion config/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,19 @@
</rule>

<rule ref="rulesets/java/migrating.xml"/>
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseTestAnnotation">
<properties>
<!-- It is not a UT. -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='ModuleUpdate'] and //MethodDeclaration[@Name='testChange']"/>
</properties>
</rule>

<rule ref="rulesets/java/naming.xml">
<!-- we use CheckstyleCustomShortVariable, to control lenght (will be fixed in PMD 5.4) and skip Override methods -->
<exclude name="ShortVariable"/>
<!-- we already have AbstractClassName for checking Abstract class name. It is annoying to set suppression in both
checkstyle and PMD. -->
<exclude name="AbstractNaming"/>
</rule>
<rule name="CheckstyleCustomShortVariable"
message="Avoid variables with short names that shorter than 2 symbols: {0}"
Expand All @@ -164,7 +173,6 @@
</property>
</properties>
</rule>
<rule ref="rulesets/java/naming.xml/AbstractNaming" />
<rule ref="rulesets/java/naming.xml/LongVariable">
<properties>
<!-- nothing bad in long and descriptive variable names if only they fit line, but still keep it reasonable -->
Expand Down
2 changes: 2 additions & 0 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
<suppress checks="AvoidStaticImport" files=".*[\\/]src[\\/]test[\\/]"/>
<suppress checks="WriteTag" files=".*[\\/]src[\\/]test[\\/]"/>
<suppress checks="MultipleStringLiterals" files=".*[\\/]src[\\/]test[\\/]"/>

<suppress checks="AbstractClassName" files=".*[\\/]data[\\/]"/>
</suppressions>
50 changes: 35 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<groupId>org.apache.maven</groupId>
<artifactId>maven-jxr</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.6</version>
<scope>test</scope>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
<scope>test</scope>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>2.5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-jxr</artifactId>
<version>2.5</version>
<groupId>org.immutables</groupId>
<artifactId>gson</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
Expand All @@ -55,6 +53,26 @@
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>

<!-- Test scope dependencies. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -271,6 +289,8 @@
</check>
<instrumentation>
<excludes>
<exclude>**/Immutable*.class</exclude>
<exclude>**/GsonAdapters*.class</exclude>
</excludes>
</instrumentation>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library 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 library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.github.checkstyle.regression.data;

import org.immutables.value.Value;

/**
* Represents a XML node in regression config.
* @author LuoLiangchen
*/
@Value.Immutable
public interface ConfigNode {
/**
* The parent of this module.
* @return the parent of this module
*/
String parent();

/**
* The module name.
* @return the module name
*/
String moduleName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library 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 library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.github.checkstyle.regression.data;

import org.immutables.gson.Gson;
import org.immutables.value.Value;

/**
* Represents the information of a checkstyle module.
* @author LuoLiangchen
*/
@Gson.TypeAdapters
@Value.Immutable
public abstract class ModuleInfo {
/**
* The package name of this module.
* @return the package name of this module
*/
public abstract String packageName();

/**
* The name of this module.
* @return the name of this module.
*/
public abstract String name();

/**
* The parent of this module.
* The value should be either "TreeWalker" or "Checker".
* @return the parent of this module.
*/
public abstract String parent();

/**
* Gets the full qualified name of this module.
* @return the full qualified name of this module
*/
public String getFullName() {
return packageName() + "." + name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library 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 library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.github.checkstyle.regression.data;

import java.util.List;
import java.util.Optional;

import org.immutables.value.Value;

/**
* Represents the related changes of a checkstyle module.
* Including the basic module information, change of the module class, change
* of the corresponding test and changed of the utility classes that the module
* depends on.
* @author LuoLiangchen
*/
@Value.Immutable
public interface ModuleUpdate {
/**
* The basic information of the module.
* @return the basic information of the module
*/
ModuleInfo moduleInfo();

/**
* The change of the module class.
* @return the change of the module class
*/
GitChange moduleChange();

/**
* The change of the corresponding test class.
* @return the change of the corresponding test class
*/
Optional<GitChange> testChange();

/**
* The changes of the utility classes that the module depends on.
* @return the changes of the utility classes that the module depends on
*/
List<GitChange> utilityChanges();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library 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 library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.github.checkstyle.regression.module;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.github.checkstyle.regression.data.GitChange;
import com.github.checkstyle.regression.data.ImmutableModuleUpdate;
import com.github.checkstyle.regression.data.ModuleUpdate;

/**
* Collects all the necessary information for the generation, in module level.
* @author LuoLiangchen
*/
public final class ModuleUpdateCollector {
/** Prevents instantiation. */
private ModuleUpdateCollector() {
}

/**
* Generates the module updates from a list of changes.
* @param changes the changes source
* @return the module updates generated from the given changes
*/
public static List<ModuleUpdate> generateModuleUpdates(List<GitChange> changes) {
final Map<String, ModuleUpdate> moduleUpdates = changes.stream()
.filter(ModuleUtils::isCheckstyleModule)
.map(change -> {
return ImmutableModuleUpdate.builder()
.moduleChange(change)
.moduleInfo(ModuleUtils.convertModuleChangeToModuleInfo(change))
.build();
})
.collect(Collectors.toMap(
update -> update.moduleInfo().getFullName(), update -> update));
for (GitChange change : changes) {
if (ModuleUtils.isCheckstyleModuleTest(change)) {
final String fullName = ModuleUtils.convertModuleTestChangeToModuleFullName(change);
if (moduleUpdates.containsKey(fullName)) {
final ModuleUpdate update = ImmutableModuleUpdate
.copyOf(moduleUpdates.get(fullName))
.withTestChange(change);
moduleUpdates.put(fullName, update);
}
}
}

return moduleUpdates.values().stream().collect(Collectors.toList());
}
}
Loading

0 comments on commit 6c42f41

Please sign in to comment.