From a722e8fa43118b71bf80cfc8d3d354a0bb0b2c75 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Wed, 11 Feb 2015 15:21:01 +0000
Subject: [PATCH] OPENDJ-1749 Add plugin to check svn:eol-style
---
opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/package-info.java | 29 +++++++
opendj-svn-property-check-maven-plugin/pom.xml | 66 ++++++++++++++++
opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/CheckSVNPropertyMojo.java | 127 +++++++++++++++++++++++++++++++
3 files changed, 222 insertions(+), 0 deletions(-)
diff --git a/opendj-svn-property-check-maven-plugin/pom.xml b/opendj-svn-property-check-maven-plugin/pom.xml
new file mode 100644
index 0000000..d31c52c
--- /dev/null
+++ b/opendj-svn-property-check-maven-plugin/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0"?>
+<!--
+ ! CDDL HEADER START
+ !
+ ! The contents of this file are subject to the terms of the
+ ! Common Development and Distribution License, Version 1.0 only
+ ! (the "License"). You may not use this file except in compliance
+ ! with the License.
+ !
+ ! You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ ! or http://forgerock.org/license/CDDLv1.0.html.
+ ! See the License for the specific language governing permissions
+ ! and limitations under the License.
+ !
+ ! When distributing Covered Code, include this CDDL HEADER in each
+ ! file and include the License file at legal-notices/CDDLv1_0.txt.
+ ! If applicable, add the following below this CDDL HEADER, with the
+ ! fields enclosed by brackets "[]" replaced with your own identifying
+ ! information:
+ ! Portions Copyright [yyyy] [name of copyright owner]
+ !
+ ! CDDL HEADER END
+ !
+ ! Copyright 2015 ForgeRock AS
+ !
+ -->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>opendj-project</artifactId>
+ <groupId>org.forgerock.opendj</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>opendj-svn-property-check-maven-plugin</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Check SVN property maven plugin</name>
+ <description>
+ Checks ForgeRock source file copyrights.
+ </description>
+ <packaging>maven-plugin</packaging>
+
+ <properties>
+ <mavenVersion>3.0.4</mavenVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.twdata.maven</groupId>
+ <artifactId>mojo-executor</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.tmatesoft.svnkit</groupId>
+ <artifactId>svnkit</artifactId>
+ <version>1.8.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.4</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/CheckSVNPropertyMojo.java b/opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/CheckSVNPropertyMojo.java
new file mode 100644
index 0000000..b29a90a
--- /dev/null
+++ b/opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/CheckSVNPropertyMojo.java
@@ -0,0 +1,127 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright 2015 ForgeRock AS
+ */
+package org.forgerock.maven;
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.tmatesoft.svn.core.SVNDepth;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.wc.ISVNStatusHandler;
+import org.tmatesoft.svn.core.wc.SVNClientManager;
+import org.tmatesoft.svn.core.wc.SVNPropertyData;
+import org.tmatesoft.svn.core.wc.SVNRevision;
+
+/**
+ * This be used to make sure that the file has the correct "svn:eol-style"
+ * property value.
+ */
+@Mojo(name = "check-svn-property", defaultPhase = LifecyclePhase.VALIDATE)
+public class CheckSVNPropertyMojo extends AbstractMojo implements ISVNStatusHandler {
+
+ /** The Maven Project. */
+ @Parameter(property = "project", required = true, readonly = true)
+ private MavenProject project;
+
+ /** The path to the root of the Subversion workspace to check. */
+ @Parameter(required = true, defaultValue = "${basedir}")
+ private String svnWorkspaceRoot;
+
+ @Parameter(required = true)
+ private String svnPropertyName;
+
+ @Parameter(required = true)
+ private String svnPropertyExpectedValue;
+
+ /**
+ * The name of the system property that may be used to prevent eol-style
+ * problems from failing the build.
+ */
+ @Parameter(property = "ignoreSvnPropertyCheckErrors", required = true, defaultValue = "false")
+ private boolean ignoreErrors;
+
+ /** The overall SVN Client Manager. */
+ private final SVNClientManager svnClientManager = SVNClientManager.newInstance();
+
+ private final List<String> errorFilePaths = new LinkedList<String>();
+
+ /** {@inheritDoc} **/
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ svnClientManager.getStatusClient().doStatus(new File(svnWorkspaceRoot), SVNRevision.WORKING,
+ SVNDepth.INFINITY, false, false, false, false, this, null);
+ } catch (Exception e) {
+ throw new MojoExecutionException("Encountered an error while examining subversion status: "
+ + e.getMessage() + "No further checks will be performed.", e);
+ }
+
+ if (!errorFilePaths.isEmpty()) {
+ getLog().warn(" Potential " + svnPropertyName + " updates needed " + "for the following files:");
+ for (String filename : errorFilePaths) {
+ getLog().warn(" " + filename);
+ }
+
+ if (!ignoreErrors) {
+ throw new MojoExecutionException("Fix " + svnPropertyName + " problems before proceeding, or "
+ + "use '-DignoreSvnPropertyCheckErrors=true' to ignore these warnings warnings.");
+ }
+ }
+ }
+
+ /**
+ * Examines the provided status item to determine whether the associated
+ * file is acceptable.
+ *
+ * @param status
+ * The SVN status information for the file of interest.
+ */
+ public void handleStatus(org.tmatesoft.svn.core.wc.SVNStatus status) throws SVNException {
+ File changedFile = status.getFile();
+ ;
+ if (!changedFile.exists() || !changedFile.isFile()) {
+ return;
+ }
+
+ try {
+ SVNPropertyData propertyData = SVNClientManager.newInstance().getWCClient()
+ .doGetProperty(changedFile, svnPropertyName, SVNRevision.BASE, SVNRevision.WORKING);
+ if (propertyData == null || !svnPropertyExpectedValue.equals(propertyData.getValue().getString())) {
+ errorFilePaths.add(changedFile.getPath());
+ }
+ } catch (SVNException se) {
+ // This could happen if the file isn't under version control.
+ getLog().warn("Impossible to check svn:eol-style for the file " + changedFile.getAbsolutePath()
+ + " you might need to add it to svn.");
+ }
+ }
+}
diff --git a/opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/package-info.java b/opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/package-info.java
new file mode 100644
index 0000000..e71290c
--- /dev/null
+++ b/opendj-svn-property-check-maven-plugin/src/main/java/org/forgerock/maven/package-info.java
@@ -0,0 +1,29 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Copyright 2015 ForgeRock AS.
+ */
+
+/** Classes implementing the maven plugin to check svn properties on tracked source files. */
+package org.forgerock.maven;
+
--
Gitblit v1.10.0