Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 15395 Details for
Bug 77026
[relengtool] allow fix copyright.. action to be more customizable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.releng.tools patch
(text/plain), 45.47 KB, created by
Amy Wu
on 2004-10-26 12:25:21 EDT
(
hide
)
Description:
org.eclipse.releng.tools patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2004-10-26 12:25:21 EDT
Size:
45.47 KB
patch
obsolete
>Index: plugin.xml >=================================================================== >RCS file: /home/eclipse/org.eclipse.releng.tools/plugin.xml,v >retrieving revision 1.2 >diff -u -r1.2 plugin.xml >--- plugin.xml 22 Jun 2004 21:01:56 -0000 1.2 >+++ plugin.xml 26 Oct 2004 15:39:37 -0000 >@@ -90,6 +90,17 @@ > id="org.eclipse.releng.tools.fixCopyrights"> > </action> > </objectContribution> >+ <objectContribution >+ objectClass="org.eclipse.core.resources.IResource" >+ id="org.eclipse.releng.internal.tools.AdvancedCopyrightContribution"> >+ <action >+ label="Advanced Fix Copyrights..." >+ class="org.eclipse.releng.tools.AdvancedFixCopyrightAction" >+ menubarPath="additions" >+ enablesFor="+" >+ id="org.eclipse.releng.tools.advancedFixCopyrights"> >+ </action> >+ </objectContribution> > </extension> > > <!-- ********** Action Sets ************** --> >@@ -110,5 +121,18 @@ > </actionSet> > </extension> > >+ <!-- ********** Preference Pages ************** --> >+ <extension point="org.eclipse.ui.preferencePages"> >+ <page >+ name="Copyright Tool" >+ class="org.eclipse.releng.tools.preferences.CopyrightPreferencePage" >+ id="org.eclipse.releng.tools.preferences.CopyrightPreferencePage"> >+ </page> >+ </extension> >+ >+ <!-- ********** Preference Initializing ************** --> >+ <extension point="org.eclipse.core.runtime.preferences"> >+ <initializer class="org.eclipse.releng.tools.preferences.RelEngPreferenceInitializer"/> >+ </extension> > > </plugin> >Index: src/org/eclipse/releng/tools/messages.properties >=================================================================== >RCS file: /home/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/messages.properties,v >retrieving revision 1.2 >diff -u -r1.2 messages.properties >--- src/org/eclipse/releng/tools/messages.properties 23 Jun 2004 19:05:07 -0000 1.2 >+++ src/org/eclipse/releng/tools/messages.properties 26 Oct 2004 15:39:37 -0000 >@@ -48,3 +48,11 @@ > RelEngPlugin.2=maps > RelEngPlugin.3=RelEngPluginResources > ProjectValidationDialog.2=Project Validation >+RelEngPreferenceInitializer.0=Copyright (c) ${date} IBM Corporation and others.\nAll rights reserved. This program and the accompanying materials\nare made available under the terms of the Eclipse Public License v1.0\nwhich accompanies this distribution, and is available at\nhttp://www.eclipse.org/legal/epl-v10.html\n\nContributors:\n IBM Corporation - initial API and implementation >+CopyrightPreferencePage.0=Use "${date}" to substitute in "creation_year, revision_year" >+CopyrightPreferencePage.1=Default creation year: >+CopyrightPreferencePage.2=Replace all existing copyright comments with this copyright template >+CopyrightPreferencePage.3=Fix up existing copyright comments to follow copyright template format >+CopyrightPreferencePage.4=Skip over properties files >+CopyrightPreferencePage.5=Copyright template >+CopyrightPreferencePage.6=Default creation year must be a positive number >Index: src/org/eclipse/releng/tools/AdvancedCopyrightComment.java >=================================================================== >RCS file: src/org/eclipse/releng/tools/AdvancedCopyrightComment.java >diff -N src/org/eclipse/releng/tools/AdvancedCopyrightComment.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/releng/tools/AdvancedCopyrightComment.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,301 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ *******************************************************************************/ >+package org.eclipse.releng.tools; >+ >+import java.io.PrintWriter; >+import java.io.StringWriter; >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+import java.util.StringTokenizer; >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.releng.tools.preferences.RelEngCopyrightConstants; >+ >+public class AdvancedCopyrightComment { >+ private static final String DATE_VAR = "${date}"; //$NON-NLS-1$ >+ private static final String NEW_LINE = "\r\n"; //$NON-NLS-1$ >+ private static final String CARRIAGE_RETURN = "\r"; //$NON-NLS-1$ >+ >+ public static final int UNKNOWN_COMMENT = -1; >+ public static final int JAVA_COMMENT = 1; >+ public static final int PROPERTIES_COMMENT = 2; >+ >+ private int commentStyle = 0; >+ private int creationYear = -1; >+ private int revisionYear = -1; >+ private List contributors; >+ private String preYearComment = null; >+ private String postYearComment = null; >+ >+ private AdvancedCopyrightComment(int commentStyle, int creationYear, int revisionYear, List contributors, String preYearComment, String postYearComment) { >+ this.commentStyle = commentStyle; >+ this.creationYear = creationYear == -1 ? getPreferenceStore().getInt(RelEngCopyrightConstants.CREATION_YEAR_KEY) : creationYear; >+ this.revisionYear = revisionYear; >+ this.contributors = contributors; >+ this.preYearComment = preYearComment; >+ this.postYearComment = postYearComment; >+ } >+ >+ private AdvancedCopyrightComment(int commentStyle, int creationYear, int revisionYear, List contributors) { >+ this(commentStyle, creationYear, revisionYear, contributors, null, null); >+ } >+ >+ public static AdvancedCopyrightComment defaultComment(int commentStyle) { >+ return new AdvancedCopyrightComment(commentStyle, -1, -1, null); >+ } >+ >+ public int getRevisionYear() { >+ return revisionYear == -1 ? creationYear : revisionYear; >+ } >+ >+ public void setRevisionYear(int year) { >+ if (revisionYear != -1 || creationYear != year) >+ revisionYear = year; >+ } >+ >+ private static String getLinePrefix(int commentStyle) { >+ switch(commentStyle) { >+ case JAVA_COMMENT: >+ return " * "; //$NON-NLS-1$ >+ case PROPERTIES_COMMENT: >+ return "# "; //$NON-NLS-1$ >+ default: >+ return null; >+ } >+ } >+ >+ private void writeCommentStart(PrintWriter writer) { >+ switch(commentStyle) { >+ case JAVA_COMMENT: >+ writer.println("/*******************************************************************************"); //$NON-NLS-1$ >+ break; >+ case PROPERTIES_COMMENT: >+ writer.println("###############################################################################"); //$NON-NLS-1$ >+ break; >+ } >+ } >+ >+ private void writeContributions(PrintWriter writer, String linePrefix) { >+ writer.println(linePrefix); >+ 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$ >+ else { >+ Iterator i = contributors.iterator(); >+ while (i.hasNext()) >+ writer.println(linePrefix + " " + (String)i.next()); //$NON-NLS-1$ >+ } >+ } >+ >+ private void writeCommentEnd(PrintWriter writer) { >+ switch(commentStyle) { >+ case JAVA_COMMENT: >+ writer.println(" *******************************************************************************/"); //$NON-NLS-1$ >+ break; >+ case PROPERTIES_COMMENT: >+ writer.println("###############################################################################"); //$NON-NLS-1$ >+ break; >+ } >+ } >+ >+ /** >+ * Get the copyright tool preference store >+ * @return >+ */ >+ private static IPreferenceStore getPreferenceStore() { >+ return RelEngPlugin.getDefault().getPreferenceStore(); >+ } >+ >+ /** >+ * Get the copyright statement in form of an array of Strings where >+ * each item is a line of the copyright statement. >+ * @return String[] >+ */ >+ private static String[] getLegalLines() { >+ StringTokenizer st = new StringTokenizer(getPreferenceStore().getString(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY), CARRIAGE_RETURN+NEW_LINE, true); >+ ArrayList lines = new ArrayList(); >+ String previous = NEW_LINE; >+ while (st.hasMoreTokens()) { >+ String current = st.nextToken(); >+ // add empty lines to array as well >+ if (NEW_LINE.equals(previous) || CARRIAGE_RETURN.equals(previous)) { >+ lines.add(current); >+ } >+ previous = current; >+ } >+ String[] stringLines = new String[lines.size()]; >+ stringLines = (String[])lines.toArray(stringLines); >+ return stringLines; >+ } >+ >+ /** >+ * Return the body of this copyright comment or null if it cannot be built. >+ */ >+ public String getCopyrightComment() { >+ // instead of overwriting an existing comment, just try to insert the new year >+ if ((preYearComment != null || postYearComment != null) && (!getPreferenceStore().getBoolean(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY))) { >+ String copyrightString = preYearComment == null ? "" : preYearComment; //$NON-NLS-1$ >+ copyrightString = copyrightString + creationYear; >+ >+ if (revisionYear != -1 && revisionYear != creationYear) >+ copyrightString = copyrightString + ", " + revisionYear; //$NON-NLS-1$ >+ >+ String endString = postYearComment == null ? "" : postYearComment; //$NON-NLS-1$ >+ copyrightString = copyrightString + postYearComment; >+ return copyrightString; >+ } >+ >+ String linePrefix = getLinePrefix(commentStyle); >+ if (linePrefix == null) >+ return null; >+ >+ StringWriter out = new StringWriter(); >+ PrintWriter writer = new PrintWriter(out); >+ try { >+ writeCommentStart(writer); >+ writeLegal(writer, linePrefix); >+ // dont do anything special with contributors right now >+// writeContributions(writer, linePrefix); >+ writeCommentEnd(writer); >+ >+ return out.toString(); >+ } finally { >+ writer.close(); >+ } >+ } >+ >+ /** >+ * Write out the copyright statement, line by line, adding in the created/revision >+ * year as well as comment line prefixes. >+ * >+ * @param writer >+ * @param linePrefix >+ */ >+ private void writeLegal(PrintWriter writer, String linePrefix) { >+ String[] legalLines = getLegalLines(); >+ for (int i=0; i < legalLines.length; ++i) { >+ String currentLine = legalLines[i]; >+ int offset = currentLine.indexOf(DATE_VAR); >+ // if this is the line, containing the ${date}, add in the year >+ if (offset > -1) { >+ writer.print(linePrefix + currentLine.substring(0, offset)+creationYear); >+ if (revisionYear != -1 && revisionYear != creationYear) >+ writer.print(", " + revisionYear); //$NON-NLS-1$ >+ writer.println(currentLine.substring(offset+DATE_VAR.length(), currentLine.length())); >+ } else { >+ // just write out the line >+ if (NEW_LINE.equals(currentLine) || CARRIAGE_RETURN.equals(currentLine)) { >+ // handle empty lines >+ writer.print(linePrefix + currentLine); >+ } else { >+ writer.println(linePrefix + currentLine); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Create an instance the same as the argument comment but with the revision year >+ * updated if needed. Return the default comment if the argument comment is null >+ * or an empty string. Return null if the argument comment is not recognized as >+ * an IBM copyright comment. >+ */ >+ public static AdvancedCopyrightComment parse(BlockComment comment, int commentStyle) { >+ AdvancedCopyrightComment copyright = null; >+ >+ if (comment == null) { >+ copyright = defaultComment(commentStyle); >+ } else { >+ // To make the comment search a little more flexible, the parse algorithm will >+ // only parse the line containing the ${date} >+ String body = comment.getContents(); >+ >+ // find the line with ${date} >+ String[] legalLines = getLegalLines(); >+ int i = 0; >+ int yearOffset = -1; >+ while (i < legalLines.length && yearOffset == -1) { >+ String line = legalLines[i]; >+ yearOffset = line.indexOf(DATE_VAR); >+ ++i; >+ } >+ // ${date} found >+ if (yearOffset != -1) { >+ String yearLine = legalLines[i-1]; >+ // split that line up and just search for the contents before and after >+ // NOTE: this won't really work well if the text surrounding the year is >+ // generic, or if the year is at the beginning or end of the line >+ String preYear = yearLine.substring(0, yearOffset); >+ String postYear = yearLine.substring(yearOffset+DATE_VAR.length(), yearLine.length()); >+ >+ int preYearOffset = body.indexOf(preYear); >+ if (preYearOffset != -1) { >+ int postYearOffset = body.indexOf(postYear, preYearOffset); >+ if (postYearOffset != -1) { >+ // then you know between that is the year >+ String yearRange = body.substring(preYearOffset+preYear.length(), postYearOffset); >+ int comma = yearRange.indexOf(","); //$NON-NLS-1$ >+ >+ String startStr = comma == -1 ? yearRange : yearRange.substring(0, comma); >+ String endStr = comma == -1 ? null : yearRange.substring(comma + 1); >+ >+ int startYear = -1; >+ if (startStr != null) >+ try { >+ startYear = Integer.parseInt(startStr.trim()); >+ } catch(NumberFormatException e) { >+ // do nothing >+ } >+ >+ int endYear = -1; >+ if (endStr != null) { >+ try { >+ endYear = Integer.parseInt(endStr.trim()); >+ } catch(NumberFormatException e) { >+ // do nothing >+ } >+ } >+ // save the copyright comment's contents before and after the year so that >+ // the comment will remain untouched rather than overwritten if the template is >+ // almost the same >+ String pre = body.substring(0, preYearOffset+preYear.length()); >+ String post = body.substring(postYearOffset); >+ >+ copyright = new AdvancedCopyrightComment(commentStyle, startYear, endYear, null, pre, post); >+ } >+ } >+ } >+ } >+ >+ // don't do anything special with contributors right now >+// int contrib = body.indexOf("Contributors:", start); //$NON-NLS-1$ >+// String contribComment = body.substring(contrib); >+// StringTokenizer tokens = new StringTokenizer(contribComment, "\r\n"); //$NON-NLS-1$ >+// tokens.nextToken(); >+// ArrayList contributors = new ArrayList(); >+// String linePrefix = getLinePrefix(commentStyle); >+// while(tokens.hasMoreTokens()) { >+// String contributor = tokens.nextToken(); >+// if (contributor.indexOf("***********************************") == -1 //$NON-NLS-1$ >+// && contributor.indexOf("###################################") == -1) { //$NON-NLS-1$ >+// int c = contributor.indexOf(linePrefix); >+// if (c != -1) >+// contributor = contributor.substring(c + linePrefix.length()); >+// contributors.add(contributor.trim()); >+// } >+// } >+// >+// return new IBMCopyrightComment(commentStyle, startYear, endYear, contributors); >+ return copyright; >+ } >+} >Index: src/org/eclipse/releng/tools/AdvancedFixCopyrightAction.java >=================================================================== >RCS file: src/org/eclipse/releng/tools/AdvancedFixCopyrightAction.java >diff -N src/org/eclipse/releng/tools/AdvancedFixCopyrightAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/releng/tools/AdvancedFixCopyrightAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,337 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ *******************************************************************************/ >+package org.eclipse.releng.tools; >+ >+import java.io.File; >+import java.io.FileNotFoundException; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.Calendar; >+import java.util.GregorianCalendar; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+import java.util.Set; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IResourceVisitor; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IAdaptable; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.releng.tools.preferences.RelEngCopyrightConstants; >+import org.eclipse.team.core.TeamException; >+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; >+import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; >+import org.eclipse.team.internal.ccvs.core.ILogEntry; >+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; >+import org.eclipse.ui.IActionDelegate; >+import org.eclipse.ui.IObjectActionDelegate; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.PlatformUI; >+ >+public class AdvancedFixCopyrightAction implements IObjectActionDelegate { >+ >+ public class MyInnerClass implements IResourceVisitor { >+ public IProgressMonitor monitor; >+ public boolean visit(IResource resource) throws CoreException { >+ if (resource.getType() == IResource.FILE) { >+ processFile((IFile) resource, monitor); >+ } >+ return true; >+ } >+ } >+ >+ private String propertiesCopyright; >+ private String javaCopyright; >+ private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ >+ private Map log = new HashMap(); >+ >+ // The current selection >+ protected IStructuredSelection selection; >+ >+ private static final int currentYear = new GregorianCalendar().get(Calendar.YEAR); >+ >+ /** >+ * Constructor for Action1. >+ */ >+ public AdvancedFixCopyrightAction() { >+ super(); >+ } >+ >+ /** >+ * Returns the selected resources. >+ * >+ * @return the selected resources >+ */ >+ protected IResource[] getSelectedResources() { >+ ArrayList resources = null; >+ if (!selection.isEmpty()) { >+ resources = new ArrayList(); >+ Iterator elements = selection.iterator(); >+ while (elements.hasNext()) { >+ Object next = elements.next(); >+ if (next instanceof IResource) { >+ resources.add(next); >+ continue; >+ } >+ if (next instanceof IAdaptable) { >+ IAdaptable a = (IAdaptable) next; >+ Object adapter = a.getAdapter(IResource.class); >+ if (adapter instanceof IResource) { >+ resources.add(adapter); >+ continue; >+ } >+ } >+ } >+ } >+ if (resources != null && !resources.isEmpty()) { >+ IResource[] result = new IResource[resources.size()]; >+ resources.toArray(result); >+ return result; >+ } >+ return new IResource[0]; >+ } >+ >+ /** >+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) >+ */ >+ public void setActivePart(IAction action, IWorkbenchPart targetPart) { >+ } >+ >+ /** >+ * @see IActionDelegate#run(IAction) >+ */ >+ public void run(IAction action) { >+ >+ log = new HashMap(); >+ try { >+ PlatformUI.getWorkbench().getProgressService().run(true, /* fork */ >+ true, /* cancellable */ >+ new IRunnableWithProgress() { >+ >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ try { >+ long start = System.currentTimeMillis(); >+ monitor.beginTask("Fixing copyrights...", //$NON-NLS-1$ >+ IProgressMonitor.UNKNOWN); >+ >+ System.out.println("Start Fixing Copyrights"); //$NON-NLS-1$ >+ IResource[] results = getSelectedResources(); >+ System.out.println("Resources selected: " //$NON-NLS-1$ >+ + results.length); >+ for (int i = 0; i < results.length; i++) { >+ IResource resource = results[i]; >+ System.out.println(resource.getName()); >+ try { >+ MyInnerClass myInnerClass = new MyInnerClass(); >+ myInnerClass.monitor = monitor; >+ resource.accept(myInnerClass); >+ } catch (CoreException e1) { >+ e1.printStackTrace(); >+ } >+ } >+ >+ writeLogs(); >+ displayLogs(); >+ System.out.println("Done Fixing Copyrights"); //$NON-NLS-1$ >+ long end = System.currentTimeMillis(); >+ System.out.println("Total time: "+(end-start)+"ms"); //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ } finally { >+ monitor.done(); >+ } >+ } >+ }); >+ } catch (InvocationTargetException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (InterruptedException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ >+ /** >+ * Lookup and return the year in which the argument file was revised. Return -1 if >+ * the revision year cannot be found. >+ */ >+ private int getCVSModificationYear(IFile file, IProgressMonitor monitor) { >+ try { >+ monitor.beginTask("Fetching logs from CVS", 100); //$NON-NLS-1$ >+ >+ try { >+ ICVSRemoteResource cvsFile = CVSWorkspaceRoot.getRemoteResourceFor(file); >+ if (cvsFile != null) { >+ // get the log entry for the revision loaded in the workspace >+ ILogEntry entry = ((ICVSRemoteFile)cvsFile) >+ .getLogEntry(new SubProgressMonitor(monitor, 100)); >+ return entry.getDate().getYear() + 1900; >+ } >+ } catch (TeamException e) { >+ // do nothing >+ } >+ } finally { >+ monitor.done(); >+ } >+ >+ return -1; >+ } >+ >+ /** >+ * >+ */ >+ private void writeLogs() { >+ >+ FileOutputStream aStream; >+ try { >+ File aFile = new File(Platform.getLocation().toFile(), >+ "copyrightLog.txt"); //$NON-NLS-1$ >+ aStream = new FileOutputStream(aFile); >+ Set aSet = log.entrySet(); >+ Iterator errorIterator = aSet.iterator(); >+ while (errorIterator.hasNext()) { >+ Map.Entry anEntry = (Map.Entry) errorIterator.next(); >+ String errorDescription = (String) anEntry.getKey(); >+ aStream.write(errorDescription.getBytes()); >+ aStream.write(newLine.getBytes()); >+ List fileList = (List) anEntry.getValue(); >+ Iterator listIterator = fileList.iterator(); >+ while (listIterator.hasNext()) { >+ String fileName = (String) listIterator.next(); >+ aStream.write(" ".getBytes()); //$NON-NLS-1$ >+ aStream.write(fileName.getBytes()); >+ aStream.write(newLine.getBytes()); >+ } >+ } >+ aStream.close(); >+ } catch (FileNotFoundException e) { >+ e.printStackTrace(); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ } >+ } >+ >+ private void displayLogs() { >+ >+ Set aSet = log.entrySet(); >+ Iterator errorIterator = aSet.iterator(); >+ while (errorIterator.hasNext()) { >+ Map.Entry anEntry = (Map.Entry) errorIterator.next(); >+ String errorDescription = (String) anEntry.getKey(); >+ System.out.println(errorDescription); >+ List fileList = (List) anEntry.getValue(); >+ Iterator listIterator = fileList.iterator(); >+ while (listIterator.hasNext()) { >+ String fileName = (String) listIterator.next(); >+ System.out.println(" " + fileName); //$NON-NLS-1$ >+ } >+ } >+ } >+ >+ /** >+ * @param file >+ */ >+ private void processFile(IFile file, IProgressMonitor monitor) { >+ SourceFile aSourceFile; >+ >+ String extension = file.getFileExtension(); >+ if (extension == null) >+ return; >+ monitor.subTask(file.getFullPath().toOSString()); >+ int fileType = AdvancedCopyrightComment.UNKNOWN_COMMENT; >+ extension = extension.toLowerCase(); >+ if (extension.equals("java")) { //$NON-NLS-1$ >+ fileType = AdvancedCopyrightComment.JAVA_COMMENT; >+ aSourceFile = new JavaFile(file); >+ } else if (extension.equals("properties")) { //$NON-NLS-1$ >+ // if stop processing if ignoring properties files >+ if (RelEngPlugin.getDefault().getPreferenceStore().getBoolean(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY)) { >+ return; >+ } >+ fileType = AdvancedCopyrightComment.PROPERTIES_COMMENT; >+ aSourceFile = new PropertiesFile(file); >+ } else >+ return; >+ >+ if (aSourceFile.hasMultipleCopyrights()) { >+ warn(file, null, "Multiple copyrights found. File UNCHANGED."); //$NON-NLS-1$//$NON-NLS-2$ >+ return; >+ } >+ >+ BlockComment copyrightComment = aSourceFile.firstCopyrightComment(); >+ AdvancedCopyrightComment ibmCopyright = AdvancedCopyrightComment.parse(copyrightComment, fileType); >+ if (ibmCopyright == null) { >+ // if replacing all existing comments, use default copyright comment >+ if (RelEngPlugin.getDefault().getPreferenceStore().getBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY)) { >+ warn(file, copyrightComment, "Could not interpret copyright comment, using default comment"); //$NON-NLS-1$ >+ ibmCopyright = AdvancedCopyrightComment.defaultComment(fileType); >+ } else { >+ warn(file, copyrightComment, "Could not interpret copyright comment"); //$NON-NLS-1$ >+ return; >+ } >+ } >+ >+ // figure out if the comment should be updated by comparing the date range >+ // in the comment to the last modification time provided by CVS >+ >+ int revised = ibmCopyright.getRevisionYear(); >+ int lastMod = revised; >+ if (lastMod < currentYear) >+ lastMod = getCVSModificationYear(file, new NullProgressMonitor()); >+ >+ // only exit if existing copyright comment already contains the year >+ // of last modification >+ if (lastMod <= revised && (copyrightComment != null)) >+ return; >+ >+ // either replace old copyright or put the new one at the top of the file >+ ibmCopyright.setRevisionYear(lastMod); >+ if (copyrightComment == null) >+ aSourceFile.insert(ibmCopyright.getCopyrightComment()); >+ else { >+ if (!copyrightComment.atTop()) >+ warn(file, copyrightComment, "Old copyright not at start of file, new copyright replaces old in same location"); //$NON-NLS-1$ >+ aSourceFile.replace(copyrightComment, ibmCopyright.getCopyrightComment()); >+ } >+ } >+ >+ private void warn(IFile file, BlockComment firstBlockComment, >+ String errorDescription) { >+ List aList = (List) log.get(errorDescription); >+ if (aList == null) { >+ aList = new ArrayList(); >+ log.put(errorDescription, aList); >+ } >+ aList.add(file.getName()); >+ } >+ >+ /** >+ * @see IActionDelegate#selectionChanged(IAction, ISelection) >+ */ >+ public void selectionChanged(IAction action, ISelection selection) { >+ if (selection instanceof IStructuredSelection) { >+ this.selection = (IStructuredSelection) selection; >+ } >+ } >+ >+} >Index: src/org/eclipse/releng/tools/preferences/CopyrightPreferencePage.java >=================================================================== >RCS file: src/org/eclipse/releng/tools/preferences/CopyrightPreferencePage.java >diff -N src/org/eclipse/releng/tools/preferences/CopyrightPreferencePage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/releng/tools/preferences/CopyrightPreferencePage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,305 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ *******************************************************************************/ >+package org.eclipse.releng.tools.preferences; >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.preference.PreferencePage; >+import org.eclipse.jface.text.Document; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.source.SourceViewer; >+import org.eclipse.jface.text.source.SourceViewerConfiguration; >+import org.eclipse.releng.tools.Messages; >+import org.eclipse.releng.tools.RelEngPlugin; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.KeyAdapter; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPreferencePage; >+ >+/** >+ * Copyright tools preference page >+ */ >+public class CopyrightPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { >+ private Composite fComposite; >+ private Label fCopyrightLabel; >+ private SourceViewer fEditor; >+ private Text fInstructions; >+ private Label fCreationYearLabel; >+ private Text fCreationYear; >+ private Button fReplaceAllExisting; >+ private Button fFixExisting; >+ private Button fIgnoreProperties; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) >+ */ >+ public void init(IWorkbench workbench) { >+ // TODO Auto-generated method stub >+ >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) >+ */ >+ protected Control createContents(Composite parent) { >+ Font font = parent.getFont(); >+ >+ //The main composite >+ fComposite = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 2; >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ fComposite.setLayout(layout); >+ fComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ fComposite.setFont(font); >+ >+ // copyright template editor >+ fEditor = createEditor(fComposite); >+ >+ GridData data = new GridData(GridData.FILL_HORIZONTAL); >+ data.horizontalSpan = 2; >+ data.horizontalIndent = 0; >+ fInstructions = new Text(fComposite, SWT.READ_ONLY); >+ fInstructions.setText(Messages.getString("CopyrightPreferencePage.0")); //$NON-NLS-1$ >+ fInstructions.setLayoutData(data); >+ >+ // default creation year >+ fCreationYearLabel = new Label(fComposite, SWT.NONE); >+ fCreationYearLabel.setText(Messages.getString("CopyrightPreferencePage.1")); //$NON-NLS-1$ >+ fCreationYear = new Text(fComposite, SWT.BORDER); >+ fCreationYear.setTextLimit(4); >+ >+ // replace all existing copyright statement >+ fReplaceAllExisting = new Button(fComposite, SWT.CHECK); >+ fReplaceAllExisting.setText(Messages.getString("CopyrightPreferencePage.2")); //$NON-NLS-1$ >+ data = new GridData(); >+ data.horizontalSpan = 2; >+ fReplaceAllExisting.setLayoutData(data); >+ >+ // fix up existing copyright statement >+ fFixExisting = new Button(fComposite, SWT.CHECK); >+ fFixExisting.setText(Messages.getString("CopyrightPreferencePage.3")); //$NON-NLS-1$ >+ data = new GridData(); >+ data.horizontalSpan = 2; >+ fFixExisting.setLayoutData(data); >+ >+ // ignore properties files >+ fIgnoreProperties = new Button(fComposite, SWT.CHECK); >+ fIgnoreProperties.setText(Messages.getString("CopyrightPreferencePage.4")); //$NON-NLS-1$ >+ data = new GridData(); >+ data.horizontalSpan = 2; >+ fIgnoreProperties.setLayoutData(data); >+ >+ KeyListener listener1 = new KeyAdapter() { >+ /* (non-Javadoc) >+ * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) >+ */ >+ public void keyReleased(KeyEvent e) { >+ validateValues(); >+ } >+ }; >+ fCreationYear.addKeyListener(listener1); >+ >+ SelectionListener listener2 = new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleReplaceAllEnabled(fReplaceAllExisting.getSelection(), fFixExisting.getSelection()); >+ } >+ }; >+ fReplaceAllExisting.addSelectionListener(listener2); >+ >+ initializeValues(); >+ return fComposite; >+ } >+ >+ /** >+ * Create the sourceviewer editor to be used to edit the copyright template >+ */ >+ private SourceViewer createEditor(Composite parent) { >+ fCopyrightLabel = new Label(parent, SWT.NONE); >+ fCopyrightLabel.setText(Messages.getString("CopyrightPreferencePage.5")); //$NON-NLS-1$ >+ GridData data= new GridData(); >+ data.horizontalSpan= 2; >+ fCopyrightLabel.setLayoutData(data); >+ >+ SourceViewer viewer= createViewer(parent); >+ >+ IDocument document= new Document(); >+ viewer.setEditable(true); >+ viewer.setDocument(document); >+ >+ // just use a default 10 lines >+ int nLines = 10; >+// int nLines= document.getNumberOfLines(); >+// if (nLines < 5) { >+// nLines= 5; >+// } else if (nLines > 12) { >+// nLines= 12; >+// } >+ >+ Control control= viewer.getControl(); >+ data= new GridData(GridData.FILL_HORIZONTAL); >+ data.widthHint= convertWidthInCharsToPixels(80); >+ data.heightHint= convertHeightInCharsToPixels(nLines); >+ data.horizontalSpan = 2; >+ control.setLayoutData(data); >+ >+ // TODO add content assist support >+// viewer.addTextListener(new ITextListener() { >+// public void textChanged(TextEvent event) { >+// if (event.getDocumentEvent() != null) >+// doSourceChanged(event.getDocumentEvent().getDocument()); >+// } >+// }); >+// >+// viewer.addSelectionChangedListener(new ISelectionChangedListener() { >+// public void selectionChanged(SelectionChangedEvent event) { >+// updateSelectionDependentActions(); >+// } >+// }); >+// >+// viewer.prependVerifyKeyListener(new VerifyKeyListener() { >+// public void verifyKey(VerifyEvent event) { >+// handleVerifyKeyPressed(event); >+// } >+// }); >+ >+ return viewer; >+ } >+ >+ /** >+ * Creates the viewer to be used to display the copyright. >+ * >+ * @param parent the parent composite of the viewer >+ * @return a configured <code>SourceViewer</code> >+ */ >+ private SourceViewer createViewer(Composite parent) { >+ SourceViewer viewer= new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); >+ SourceViewerConfiguration configuration= new SourceViewerConfiguration() { >+ // TODO add content assist support >+// public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { >+// >+// ContentAssistant assistant= new ContentAssistant(); >+// assistant.enableAutoActivation(true); >+// assistant.enableAutoInsert(true); >+// assistant.setContentAssistProcessor(fTemplateProcessor, IDocument.DEFAULT_CONTENT_TYPE); >+// return assistant; >+// } >+ }; >+ viewer.configure(configuration); >+ return viewer; >+ } >+ >+ /** >+ * Initialize the control values in this preference page >+ */ >+ private void initializeValues() { >+ IPreferenceStore store = getPreferenceStore(); >+ >+ fEditor.getDocument().set(store.getString(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY)); >+ fCreationYear.setText(store.getString(RelEngCopyrightConstants.CREATION_YEAR_KEY)); >+ fReplaceAllExisting.setSelection(store.getBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY)); >+ handleReplaceAllEnabled(fReplaceAllExisting.getSelection(), store.getBoolean(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY)); >+ fIgnoreProperties.setSelection(store.getBoolean(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY)); >+ } >+ >+ /** >+ * Validate the control values in this preference page >+ */ >+ private void validateValues() { >+ String ERROR_MESSAGE = Messages.getString("CopyrightPreferencePage.6"); //$NON-NLS-1$ >+ >+ String errorMsg = null; >+ >+ // creation year must be an integer >+ String creationYear = fCreationYear.getText(); >+ try { >+ int year = Integer.parseInt(creationYear); >+ if (year < 0) { >+ errorMsg = ERROR_MESSAGE; >+ } >+ } catch (NumberFormatException e) { >+ errorMsg = ERROR_MESSAGE; >+ } >+ setErrorMessage(errorMsg); >+ setValid(errorMsg == null); >+ } >+ >+ /** >+ * Handles when the Replace all copyrights checkbox is checked/unchecked. >+ * When checked, fix up copyright checkbox is disabled and checked >+ * When unchecked, fix up copyright checkbox is enabled and set to default value >+ * @param replaceAll >+ * @param defaultValue >+ */ >+ private void handleReplaceAllEnabled(boolean replaceAll, boolean defaultValue) { >+ if (fReplaceAllExisting.isEnabled() && !replaceAll) >+ fFixExisting.setEnabled(true); >+ else >+ fFixExisting.setEnabled(false); >+ >+ if (replaceAll) { >+ fFixExisting.setSelection(replaceAll); >+ } else { >+ fFixExisting.setSelection(defaultValue); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore() >+ */ >+ protected IPreferenceStore doGetPreferenceStore() { >+ return RelEngPlugin.getDefault().getPreferenceStore(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults() >+ */ >+ protected void performDefaults() { >+ IPreferenceStore store = getPreferenceStore(); >+ >+ fEditor.getDocument().set(store.getDefaultString(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY)); >+ fCreationYear.setText(store.getDefaultString(RelEngCopyrightConstants.CREATION_YEAR_KEY)); >+ fReplaceAllExisting.setSelection(getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY)); >+ handleReplaceAllEnabled(fReplaceAllExisting.getSelection(), getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY)); >+ fIgnoreProperties.setSelection(getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY)); >+ >+ super.performDefaults(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.preference.IPreferencePage#performOk() >+ */ >+ public boolean performOk() { >+ IPreferenceStore store = getPreferenceStore(); >+ >+ store.setValue(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY, fEditor.getDocument().get()); >+ store.setValue(RelEngCopyrightConstants.CREATION_YEAR_KEY, fCreationYear.getText()); >+ store.setValue(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY, fReplaceAllExisting.getSelection()); >+ store.setValue(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY, fFixExisting.getSelection()); >+ store.setValue(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY, fIgnoreProperties.getSelection()); >+ >+ RelEngPlugin.getDefault().savePluginPreferences(); >+ >+ return super.performOk(); >+ } >+} >Index: src/org/eclipse/releng/tools/preferences/RelEngCopyrightConstants.java >=================================================================== >RCS file: src/org/eclipse/releng/tools/preferences/RelEngCopyrightConstants.java >diff -N src/org/eclipse/releng/tools/preferences/RelEngCopyrightConstants.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/releng/tools/preferences/RelEngCopyrightConstants.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ *******************************************************************************/ >+package org.eclipse.releng.tools.preferences; >+ >+/** >+ * Contains all the constants used by the releng copyright tool >+ */ >+public class RelEngCopyrightConstants { >+ public final static String COPYRIGHT_TEMPLATE_KEY = "org.eclipse.releng.tools.copyrightTemplate"; //$NON-NLS-1$ >+ public final static String CREATION_YEAR_KEY = "org.eclipse.releng.tools.creationYear"; //$NON-NLS-1$ >+ public final static String FIX_UP_EXISTING_KEY = "org.eclipse.releng.tools.fixUpExisting"; //$NON-NLS-1$ >+ public final static String REPLACE_ALL_EXISTING_KEY = "org.eclipse.releng.tools.replaceAllExisting"; //$NON-NLS-1$ >+ public final static String IGNORE_PROPERTIES_KEY = "org.eclipse.releng.tools.ignoreProperties"; //$NON-NLS-1$ >+} >Index: src/org/eclipse/releng/tools/preferences/RelEngPreferenceInitializer.java >=================================================================== >RCS file: src/org/eclipse/releng/tools/preferences/RelEngPreferenceInitializer.java >diff -N src/org/eclipse/releng/tools/preferences/RelEngPreferenceInitializer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/releng/tools/preferences/RelEngPreferenceInitializer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ *******************************************************************************/ >+package org.eclipse.releng.tools.preferences; >+ >+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.releng.tools.Messages; >+import org.eclipse.releng.tools.RelEngPlugin; >+ >+/** >+ * Initializes default preferences for release engineering tool >+ */ >+public class RelEngPreferenceInitializer extends AbstractPreferenceInitializer { >+ private final String LEGAL_LINE = Messages.getString("RelEngPreferenceInitializer.0"); //$NON-NLS-1$ >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() >+ */ >+ public void initializeDefaultPreferences() { >+ IPreferenceStore store = RelEngPlugin.getDefault().getPreferenceStore(); >+ store.setDefault(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY, LEGAL_LINE); >+ store.setDefault(RelEngCopyrightConstants.CREATION_YEAR_KEY, 2003); >+ store.setDefault(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY, false); >+ store.setDefault(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY, false); >+ store.setDefault(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY, false); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 77026
:
15395
|
15396
|
15704
|
15705