Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-releng-dev] Fix for the copyright tool


Hi,

Here is a patch to apply on HEAD to fix a bug in the copyright tool.

With the actual tool, such comment:
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     IBM Corporation - added the following constants
 *                                                                   NonStaticAccessToStaticField
 *                                                                   NonStaticAccessToStaticMethod
 *                                                                   Task
 *                                                                   ExpressionShouldBeAVariable
 *                                                                   AssignmentHasNoEffect
 *     IBM Corporation - added the following constants
 *                                                                   TooManySyntheticArgumentSlots
 *                                                                   TooManyArrayDimensions
 *                                                                   TooManyBytesForStringConstant
 *                                                                   TooManyMethods
 *                                                                   TooManyFields
 *                                                                   NonBlankFinalLocalAssignment
 *                                                                   ObjectCannotHaveSuperTypes

would become something like this:

/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     IBM Corporation - added the following constants
 *     *                                                                   NonStaticAccessToStaticField
 *     *                                                                   NonStaticAccessToStaticMethod
 *     *                                                                   Task
 *     *                                                                   ExpressionShouldBeAVariable
 *     *                                                                   AssignmentHasNoEffect
 *     IBM Corporation - added the following constants
 *     *                                                                   TooManySyntheticArgumentSlots
 *     *                                                                   TooManyArrayDimensions
 *     *                                                                   TooManyBytesForStringConstant
 *     *                                                                   TooManyMethods
 *     *                                                                   TooManyFields
 *     *                                                                   NonBlankFinalLocalAssignment

This is not what I expect.

With the patch, you get something like this:

/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     IBM Corporation - added the following constants
 *                                                                   NonStaticAccessToStaticField
 *                                                                   NonStaticAccessToStaticMethod
 *                                                                   Task
 *                                                                   ExpressionShouldBeAVariable
 *                                                                   AssignmentHasNoEffect
 *     IBM Corporation - added the following constants
 *                                                                   TooManySyntheticArgumentSlots
 *                                                                   TooManyArrayDimensions
 *                                                                   TooManyBytesForStringConstant
 *                                                                   TooManyMethods
 *                                                                   TooManyFields
 *                                                                   NonBlankFinalLocalAssignment

I found the problem with the interface org.eclipse.jdt.core.compiler.IProblem, but it could occur at other places.

The patch is doing the following thing.

1) The line prefix is only " *" instead of " * ". I don't trim the contributors in order to preserve indentation. I check whether the first character is a whitespace. If this is the case I don't add an extra whitespace.
2) I also added action for a single IFile or a IFolder. This helps to run the tool on a subpart of a project.

Another solution would be to leave contributors line as is.

Hope this help,

Olivier

Index: plugin.xml
===================================================================
RCS file: /home/eclipse/org.eclipse.releng.tools/plugin.xml,v
retrieving revision 1.4
diff -u -r1.4 plugin.xml
--- plugin.xml	22 Feb 2005 19:47:37 -0000	1.4
+++ plugin.xml	22 Feb 2005 21:46:58 -0000
@@ -91,6 +91,30 @@
                id="org.eclipse.releng.tools.fixCopyrights">
          </action>
       </objectContribution>
+      <objectContribution
+      		adaptable="true"
+            objectClass="org.eclipse.core.resources.IFolder"
+            id="org.eclipse.releng.internal.tools.CopyrightContribution">
+         <action
+               label="Fix Copyrights..."
+               class="org.eclipse.releng.tools.FixCopyrightAction"
+               menubarPath="additions"
+               enablesFor="+"
+               id="org.eclipse.releng.tools.fixCopyrights">
+         </action>
+      </objectContribution>
+      <objectContribution
+      		adaptable="true"
+            objectClass="org.eclipse.core.resources.IFile"
+            id="org.eclipse.releng.internal.tools.CopyrightContribution">
+         <action
+               label="Fix Copyrights..."
+               class="org.eclipse.releng.tools.FixCopyrightAction"
+               menubarPath="additions"
+               enablesFor="+"
+               id="org.eclipse.releng.tools.fixCopyrights">
+         </action>
+      </objectContribution>
    </extension>
    
    	<!-- ********** Action Sets ************** -->
Index: src/org/eclipse/releng/tools/IBMCopyrightComment.java
===================================================================
RCS file: /home/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/IBMCopyrightComment.java,v
retrieving revision 1.6
diff -u -r1.6 IBMCopyrightComment.java
--- src/org/eclipse/releng/tools/IBMCopyrightComment.java	21 Feb 2005 18:05:38 -0000	1.6
+++ src/org/eclipse/releng/tools/IBMCopyrightComment.java	22 Feb 2005 21:46:58 -0000
@@ -96,9 +96,11 @@
    	        if (contributor.indexOf("***********************************") == -1 //$NON-NLS-1$
    	         && contributor.indexOf("###################################") == -1) { //$NON-NLS-1$
    	            int c = contributor.indexOf(linePrefix);
-   	            if (c != -1)
+   	            if (c == 0) {
+					// it has to be at the beginning of the line
    	                contributor = contributor.substring(c + linePrefix.length());
-   	            contributors.add(contributor.trim());
+   	            }
+   	            contributors.add(contributor);
    	        }
    	    }
 
@@ -117,7 +119,7 @@
     private static String getLinePrefix(int commentStyle) {
         switch(commentStyle) {
         case JAVA_COMMENT:
-            return " * ";  //$NON-NLS-1$
+            return " *";  //$NON-NLS-1$
         case PROPERTIES_COMMENT:
             return "# "; //$NON-NLS-1$
         default:
@@ -159,27 +161,37 @@
 	}
 
 	private void writeLegal(PrintWriter writer, String linePrefix) {
-		writer.print(linePrefix + "Copyright (c) " + creationYear); //$NON-NLS-1$
+		writer.print(linePrefix + " Copyright (c) " + creationYear); //$NON-NLS-1$
 		if (revisionYear != -1 && revisionYear != creationYear)
 	        writer.print(", " + revisionYear); //$NON-NLS-1$
 		writer.println(" IBM Corporation and others."); //$NON-NLS-1$
 
-		writer.println(linePrefix + "All rights reserved. This program and the accompanying materials"); //$NON-NLS-1$
-		writer.println(linePrefix + "are made available under the terms of the Eclipse Public License v1.0"); //$NON-NLS-1$
-		writer.println(linePrefix + "which accompanies this distribution, and is available at"); //$NON-NLS-1$
-		writer.println(linePrefix + "http://www.eclipse.org/legal/epl-v10.html";); //$NON-NLS-1$
+		writer.println(linePrefix + " All rights reserved. This program and the accompanying materials"); //$NON-NLS-1$
+		writer.println(linePrefix + " are made available under the terms of the Eclipse Public License v1.0"); //$NON-NLS-1$
+		writer.println(linePrefix + " which accompanies this distribution, and is available at"); //$NON-NLS-1$
+		writer.println(linePrefix + " http://www.eclipse.org/legal/epl-v10.html";); //$NON-NLS-1$
 	}
 
 	private void writeContributions(PrintWriter writer, String linePrefix) {
 		writer.println(linePrefix);
-		writer.println(linePrefix + "Contributors:"); //$NON-NLS-1$
+		writer.println(linePrefix + " Contributors:"); //$NON-NLS-1$
 
 		if (contributors == null || contributors.size() <= 0)
-		    writer.println(linePrefix + "    IBM Corporation - initial API and implementation"); //$NON-NLS-1$
+		    writer.println(linePrefix + "     IBM Corporation - initial API and implementation"); //$NON-NLS-1$
 		else {
 			Iterator i = contributors.iterator();
-			while (i.hasNext())
-			    writer.println(linePrefix + "    " + (String)i.next());  //$NON-NLS-1$
+			while (i.hasNext()) {
+				String contributor = (String) i.next();
+				if (contributor.length() > 0) {
+					if (Character.isWhitespace(contributor.charAt(0))) {
+					    writer.println(linePrefix + contributor);  //$NON-NLS-1$
+					} else {
+					    writer.println(linePrefix + " " + contributor);  //$NON-NLS-1$
+					}
+				} else {
+				    writer.println(linePrefix);  //$NON-NLS-1$
+				}
+			}
 		}
 	}
 

Back to the top