Simple fixes to code and flip the switch.
Change-Id: I06bdd3d3e49c503c390a8cb46ecfeaa8fdf405d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
*/
public interface BasicCodeGenerator {
/**
- * Generate sources from provided {@link SchemaContext}
+ * Generate sources from provided {@link SchemaContext}.
*
* @param context
* parsed from YANG files
throws IOException;
/**
- * Generate sources from provided {@link SchemaContext}
+ * Generate sources from provided {@link SchemaContext}.
*
* @param context
* parsed from YANG files
* @param moduleResourcePathResolver
* Function converting a local module to the packaged resource path
* @return collection of files that were generated from schema context
- * @throws IOException
*/
default Collection<File> generateSources(final SchemaContext context, final File outputBaseDir,
final Set<Module> currentModules,
/**
* Provided map contains all configuration that was set in pom for code
- * generator in additionalConfiguration tag
- *
- * @param additionalConfiguration
+ * generator in additionalConfiguration tag.
*/
void setAdditionalConfig(Map<String, String> additionalConfiguration);
/**
* Provided folder is marked as resources and its content will be packaged
- * in resulting jar. Feel free to add necessary resources
- *
- * @param resourceBaseDir
+ * in resulting jar. Feel free to add necessary resources.
*/
void setResourceBaseDir(File resourceBaseDir);
}
/**
* Provided maven project object. Any additional information about current
* maven project can be accessed from it.
- *
- * @param project
*/
void setMavenProject(MavenProject project);
}
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
import org.apache.maven.project.MavenProject;
/**
- * Base complex configuration arguments
+ * Base complex configuration arguments.
*/
public abstract class ConfigArg {
private final File targetGeneratedSources;
- public GeneratedDirectories(MavenProject project) {
+ GeneratedDirectories(MavenProject project) {
this.targetGeneratedSources = new File(project.getBuild().getDirectory(), "generated-sources");
}
final class Util {
/**
- * It isn't desirable to create instances of this class
+ * It isn't desirable to create instances of this class.
*/
private Util() {
}
private static final Logger LOG = LoggerFactory.getLogger(Util.class);
- static Collection<File> listFiles(final File root, final Collection<File> excludedFiles) throws FileNotFoundException {
+ static Collection<File> listFiles(final File root, final Collection<File> excludedFiles)
+ throws FileNotFoundException {
if (!root.exists()) {
LOG.warn("{} YANG source directory {} not found. No code will be generated.", YangToSourcesProcessor
.LOG_PREFIX, root.toString());
if (artifact.getGroupId().equals(d.getGroupId()) && artifact.getArtifactId().equals(d.getArtifactId())) {
if (!(artifact.getVersion().equals(d.getVersion()))) {
LOG.warn("{} Dependency resolution conflict:", YangToSourcesProcessor.LOG_PREFIX);
- LOG.warn("{} '{}' dependency [{}] has different version than one declared in current project [{}]" +
- ". It is recommended to fix this problem because it may cause compilation errors.",
+ LOG.warn("{} '{}' dependency [{}] has different version than one declared in current project [{}]"
+ + ". It is recommended to fix this problem because it may cause compilation errors.",
YangToSourcesProcessor.LOG_PREFIX, YangToSourcesMojo.PLUGIN_NAME, artifact, d);
}
}
}
}
+ @SuppressWarnings("checkstyle:illegalCatch")
static YangsInZipsResult findYangFilesInDependenciesAsStream(final MavenProject project)
throws MojoFailureException {
List<YangSourceFromDependency> yangsFromDependencies = new ArrayList<>();
}
/**
- * Find all dependencies which contains yang sources
- *
+ * Find all dependencies which contains yang sources.
* Returns collection of YANG files and Zip files which contains YANG files.
*
- * FIXME: Rename to what class is actually doing.
- *
- * @param project
- * @return
- * @throws MojoFailureException
*/
+ // FIXME: Rename to what class is actually doing.
+ @SuppressWarnings("checkstyle:illegalCatch")
static Collection<File> findYangFilesInDependencies(final MavenProject project) throws MojoFailureException {
final List<File> yangsFilesFromDependencies = new ArrayList<>();
private final File source;
- public YangSourceFromFile(File source) {
+ YangSourceFromFile(File source) {
this.source = Preconditions.checkNotNull(source);
}
* </ol></li>
* </ol>
*/
-@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
+@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+ requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
public final class YangToSourcesMojo extends AbstractMojo {
public static final String PLUGIN_NAME = "org.opendaylight.yangtools:yang-maven-plugin";
@Component
private RepositorySystem repoSystem;
- @Parameter( readonly = true, defaultValue = "${localRepository}" )
+ @Parameter(readonly = true, defaultValue = "${localRepository}")
private ArtifactRepository localRepository;
- @Parameter( readonly = true, defaultValue = "${project.remoteArtifactRepositories}" )
+ @Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
private List<ArtifactRepository> remoteRepos;
// When set to "true", then the execution of the plugin is disabled
- @Parameter( property = "yang.skip" )
- private String yang_skip;
+ @Parameter(property = "yang.skip")
+ private String yangSkip;
public YangToSourcesMojo() {
}
yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
excludedFiles, codeGeneratorArgs, project, inspectDependencies);
}
- yangToSourcesProcessor.conditionalExecute("true".equals(yang_skip));
+ yangToSourcesProcessor.conditionalExecute("true".equals(yangSkip));
}
private static List<CodeGeneratorArg> processCodeGenerators(final CodeGeneratorArg[] codeGenerators) {
}
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private ContextHolder processYang() throws MojoExecutionException {
SchemaContext resolveSchemaContext;
List<Closeable> closeables = new ArrayList<>();
} catch (Exception e) {
LOG.error("{} Unable to parse {} files from {}", LOG_PREFIX, Util.YANG_SUFFIX, yangFilesRootDir, e);
Throwable rootCause = Throwables.getRootCause(e);
- throw new MojoExecutionException(LOG_PREFIX + " Unable to parse " + Util.YANG_SUFFIX + " files from " +
- yangFilesRootDir, rootCause);
+ throw new MojoExecutionException(LOG_PREFIX + " Unable to parse " + Util.YANG_SUFFIX + " files from "
+ + yangFilesRootDir, rootCause);
}
}
}
/**
- * Call generate on every generator from plugin configuration
+ * Call generate on every generator from plugin configuration.
*/
+ @SuppressWarnings("checkstyle:illegalCatch")
private void generateSources(final ContextHolder context) throws MojoFailureException {
if (codeGenerators.size() == 0) {
LOG.warn("{} No code generators provided", LOG_PREFIX);
}
/**
- * Instantiate generator from class and call required method
+ * Instantiate generator from class and call required method.
*/
private void generateSourcesWithOneGenerator(final ContextHolder context, final CodeGeneratorArg codeGeneratorCfg)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
codeGeneratorCfg.check();
- BasicCodeGenerator g = getInstance(codeGeneratorCfg.getCodeGeneratorClass(), BasicCodeGenerator.class);
+ final BasicCodeGenerator g = getInstance(codeGeneratorCfg.getCodeGeneratorClass(), BasicCodeGenerator.class);
LOG.info("{} Code generator instantiated from {}", LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass());
final File outputDir = codeGeneratorCfg.getOutputBaseDir(project);
if (outputDir == null) {
- throw new NullPointerException("outputBaseDir is null. Please provide a valid outputBaseDir value in the " +
- "pom.xml");
+ throw new NullPointerException("outputBaseDir is null. Please provide a valid outputBaseDir value in the "
+ + "pom.xml");
}
project.addCompileSourceRoot(outputDir.getAbsolutePath());
}
/**
- * Instantiate object from fully qualified class name
+ * Instantiate object from fully qualified class name.
*/
private static <T> T getInstance(final String codeGeneratorClass, final Class<T> baseType) throws
ClassNotFoundException, InstantiationException, IllegalAccessException {
private static MavenProject project;
@Override
- public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir, final Set<Module> currentModules)
- throws IOException {
+ public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir,
+ final Set<Module> currentModules) throws IOException {
called++;
outputDir = outputBaseDir;
return Lists.newArrayList();
public void yangSourceInZipFileTest() throws Exception {
final ZipFile file = Mockito.mock(ZipFile.class);
final ZipEntry entry = Mockito.mock(ZipEntry.class);
- Mockito.when(entry.getSize()).thenReturn(519l);
+ Mockito.when(entry.getSize()).thenReturn(519L);
final InputStream inputStream = Mockito.mock(InputStream.class);
Mockito.when(file.getInputStream(entry)).thenReturn(inputStream);
final YangSourceInZipFile yangSource = new YangSourceInZipFile(file, entry);
private YangToSourcesProcessor proc;
@Test
- public void yangToSourceMojoTest() throws Exception{
+ public void yangToSourceMojoTest() throws Exception {
Mockito.when(this.project.getPlugin(YangToSourcesMojo.PLUGIN_NAME)).thenReturn(this.plugin);
this.mojo = new YangToSourcesMojo();
private final YangProvider inspectDependencies = Mockito.mock(YangProvider.class);
@Test
- public void yangToSourcesProcessotTest(){
+ public void yangToSourcesProcessotTest() {
Mockito.when(this.buildContext.getPath()).thenReturn("path");
YangToSourcesProcessor processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir,
ImmutableList.of(), project, dep, inspectDependencies);