mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
19.30.2015 ec9caffae2316fe403b7e1eeac01632261c7a4e6
(CR-6119) Code cleanup in copyright maven plugin
3 files modified
63 ■■■■■ changed files
opendj-copyright-maven-plugin/src/main/java/org/forgerock/maven/CopyrightAbstractMojo.java 36 ●●●●● patch | view | raw | blame | history
opendj-copyright-maven-plugin/src/main/java/org/forgerock/maven/UpdateCopyrightMojo.java 25 ●●●● patch | view | raw | blame | history
opendj-copyright-maven-plugin/src/test/java/org/forgerock/maven/UpdateCopyrightTestCase.java 2 ●●● patch | view | raw | blame | history
opendj-copyright-maven-plugin/src/main/java/org/forgerock/maven/CopyrightAbstractMojo.java
@@ -191,12 +191,10 @@
                if (!CHECKED_EXTENSIONS.contains(extension.toLowerCase())) {
                    continue;
                }
            } else {
                // We'll still want to check it if it's in a resource/bin directory.
                if (fileNameEquals("bin", changedFile.getParentFile())
                        && fileNameEquals("resource", changedFile.getParentFile().getParentFile())) {
                    continue;
                }
            } else if (fileNameEquals("bin", changedFile.getParentFile())
                    && fileNameEquals("resource", changedFile.getParentFile().getParentFile())) {
                // ignore resource/bin directory.
                continue;
            }
            if (!checkCopyrightForFile(changedFile)) {
@@ -218,28 +216,22 @@
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(changedFile));
            String line = reader.readLine();
            while (line != null) {
            String line;
            while ((line = reader.readLine()) != null) {
                String lowerLine = line.toLowerCase().trim();
                if (isCommentLine(lowerLine)) {
                    int copyrightPos = lowerLine.indexOf("copyright");
                    if (copyrightPos > 0) {
                        if (line.contains(currentYear.toString()) && line.contains(copyrightOwnerToken)) {
                            reader.close();
                            return true;
                        }
                    }
                if (isCommentLine(lowerLine)
                        && lowerLine.contains("copyright")
                        && line.contains(currentYear.toString())
                        && line.contains(copyrightOwnerToken)) {
                    reader.close();
                    return true;
                }
                line = reader.readLine();
            }
            return false;
        } catch (IOException ioe) {
            StringBuilder errorMsg = new StringBuilder().append(" Could not read file ")
                    .append(changedFile.getPath())
                    .append(" to check copyright date. No further copyright date checking will be performed.");
            throw new MojoExecutionException(errorMsg.toString());
            throw new MojoExecutionException("Could not read file " + changedFile.getPath()
                    + " to check copyright date. No further copyright date checking will be performed.");
        } finally {
            closeSilently(reader);
        }
opendj-copyright-maven-plugin/src/main/java/org/forgerock/maven/UpdateCopyrightMojo.java
@@ -173,27 +173,25 @@
                previousLine = bufferedLines.get(indexAdd);
            }
            indexAdd++;
            StringBuffer newCopyrightLine = new StringBuffer(getNewCommentedLine());
            newCopyrightLine.append(indent())
                            .append(portionsCopyrightNeeded ? portionsCopyrightStartToken : copyrightStartToken)
                            .append(" ").append(currentYear).append(" ").append(copyrightEndToken);
            if (!portionsCopyrightNeeded) {
                for (int i = 0; i < nbLinesToSkip; i++) {
                    bufferedLines.add(indexAdd++, getNewCommentedLine());
                }
            }
            bufferedLines.add(indexAdd, newCopyrightLine.toString());
            final String newCopyrightLine = getNewCommentedLine()
                    + indent() + (portionsCopyrightNeeded ? portionsCopyrightStartToken : copyrightStartToken)
                    + " " + currentYear + " " + copyrightEndToken;
            bufferedLines.add(indexAdd, newCopyrightLine);
            copyrightUpdated = true;
        }
        private void updateExistingCopyrightLine() throws Exception {
            if (portionsCopyrightNeeded && copyrightSectionPresent) {
                // Check if the line is a new copyright line
                if (curLine.contains(copyrightStartToken) && !curLine.contains(portionsCopyrightStartToken)) {
                    getLog().warn("File " + filePath + " contains old copyright line and coyright line. "
                            + "The copyright line will be replaced by a portion copyright line.");
                    curLine.replace(copyrightStartToken, portionsCopyrightStartToken);
                }
            if (portionsCopyrightNeeded && copyrightSectionPresent
                    // Is it a new copyright line?
                    && curLine.contains(copyrightStartToken) && !curLine.contains(portionsCopyrightStartToken)) {
                getLog().warn("File " + filePath + " contains old copyright line and coyright line. "
                        + "The copyright line will be replaced by a portions copyright line.");
                curLine.replace(copyrightStartToken, portionsCopyrightStartToken);
            }
            readYearSection();
            final String newCopyrightLine;
@@ -360,6 +358,7 @@
     * @throws MojoExecutionException
     *             if any
     */
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        checkCopyrights();
        for (String filePath : getIncorrectCopyrightFilePaths()) {
@@ -380,7 +379,7 @@
    }
    private String intervalToString(Integer startYear, Integer endYear) {
        return startYear.toString() + "-" + endYear;
        return startYear + "-" + endYear;
    }
    private String indent() {
opendj-copyright-maven-plugin/src/test/java/org/forgerock/maven/UpdateCopyrightTestCase.java
@@ -48,7 +48,7 @@
    private static final String[] TEST_FOLDERS = new String[] {"openam-copyrights",
        "opendj-copyrights", "openidm-copyrights"};
    /** Customs tags in tests files */
    /** Customs tags in tests files. */
    private static final String MUST_BE_REMOVE_TAG = "MUST BE REMOVED:";
    private static final String EXPECTED_OUTPUT_TAG = "EXPECTED OUTPUT:";
    private static final String YEAR_TAG = "YEAR";