Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 77026 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+24 lines)
Lines 90-95 Link Here
90
               id="org.eclipse.releng.tools.fixCopyrights">
90
               id="org.eclipse.releng.tools.fixCopyrights">
91
         </action>
91
         </action>
92
      </objectContribution>
92
      </objectContribution>
93
      <objectContribution
94
            objectClass="org.eclipse.core.resources.IResource"
95
            id="org.eclipse.releng.internal.tools.AdvancedCopyrightContribution">
96
         <action
97
               label="Advanced Fix Copyrights..."
98
               class="org.eclipse.releng.tools.AdvancedFixCopyrightAction"
99
               menubarPath="additions"
100
               enablesFor="+"
101
               id="org.eclipse.releng.tools.advancedFixCopyrights">
102
         </action>
103
      </objectContribution>
93
   </extension>
104
   </extension>
94
   
105
   
95
   	<!-- ********** Action Sets ************** -->
106
   	<!-- ********** Action Sets ************** -->
Lines 110-114 Link Here
110
	  </actionSet>
121
	  </actionSet>
111
	</extension>
122
	</extension>
112
   
123
   
124
	<!-- ********** Preference Pages ************** -->
125
	<extension point="org.eclipse.ui.preferencePages">
126
      <page
127
            name="Copyright Tool"
128
            class="org.eclipse.releng.tools.preferences.CopyrightPreferencePage"
129
            id="org.eclipse.releng.tools.preferences.CopyrightPreferencePage">
130
      </page>
131
	</extension>
132
	
133
	<!-- ********** Preference Initializing ************** -->
134
	<extension point="org.eclipse.core.runtime.preferences">
135
		<initializer class="org.eclipse.releng.tools.preferences.RelEngPreferenceInitializer"/>
136
	</extension>
113
137
114
</plugin>
138
</plugin>
(-)src/org/eclipse/releng/tools/messages.properties (+10 lines)
Lines 48-50 Link Here
48
RelEngPlugin.2=maps
48
RelEngPlugin.2=maps
49
RelEngPlugin.3=RelEngPluginResources
49
RelEngPlugin.3=RelEngPluginResources
50
ProjectValidationDialog.2=Project Validation
50
ProjectValidationDialog.2=Project Validation
51
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
52
CopyrightPreferencePage.0=Use "${date}" to substitute in "creation_year, revision_year"
53
CopyrightPreferencePage.1=Default creation year:
54
CopyrightPreferencePage.2=Replace all existing copyright comments with this copyright template
55
CopyrightPreferencePage.3=Fix up existing copyright comments to follow copyright template format
56
CopyrightPreferencePage.4=Skip over properties files
57
CopyrightPreferencePage.5=Copyright template
58
CopyrightPreferencePage.6=Default year must be a positive number
59
CopyrightPreferencePage.7=Default revision year:
60
CopyrightPreferencePage.8=Always use default revision year instead of CVS lookup
(-)src/org/eclipse/releng/tools/AdvancedCopyrightComment.java (+302 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tools;
12
13
import java.io.PrintWriter;
14
import java.io.StringWriter;
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
18
import java.util.StringTokenizer;
19
20
import org.eclipse.jface.preference.IPreferenceStore;
21
import org.eclipse.releng.tools.preferences.RelEngCopyrightConstants;
22
23
public class AdvancedCopyrightComment {
24
	private static final String DATE_VAR = "${date}"; //$NON-NLS-1$
25
	private static final String NEW_LINE = "\n"; //$NON-NLS-1$
26
27
    public static final int UNKNOWN_COMMENT = -1;
28
    public static final int JAVA_COMMENT = 1;
29
    public static final int PROPERTIES_COMMENT = 2;
30
31
    private int commentStyle = 0;
32
    private int creationYear = -1;
33
    private int revisionYear = -1;
34
    private List contributors;
35
    private String preYearComment = null;
36
    private String postYearComment = null;
37
38
    private AdvancedCopyrightComment(int commentStyle, int creationYear, int revisionYear, List contributors, String preYearComment, String postYearComment) {
39
        this.commentStyle = commentStyle;
40
       	this.creationYear = creationYear == -1 ? getPreferenceStore().getInt(RelEngCopyrightConstants.CREATION_YEAR_KEY) : creationYear;
41
        this.revisionYear = revisionYear;
42
        this.contributors = contributors;
43
        this.preYearComment = preYearComment;
44
        this.postYearComment = postYearComment;
45
    }
46
    
47
    private AdvancedCopyrightComment(int commentStyle, int creationYear, int revisionYear, List contributors) {
48
    	this(commentStyle, creationYear, revisionYear, contributors, null, null);
49
    }
50
51
    public static AdvancedCopyrightComment defaultComment(int commentStyle) {
52
        return new AdvancedCopyrightComment(commentStyle, -1, -1, null);
53
    }
54
    
55
    public int getRevisionYear() {
56
        return revisionYear == -1 ? creationYear : revisionYear;
57
    }
58
59
    public void setRevisionYear(int year) {
60
        if (revisionYear != -1 || creationYear != year)
61
            revisionYear = year;
62
    }
63
64
    private static String getLinePrefix(int commentStyle) {
65
        switch(commentStyle) {
66
        case JAVA_COMMENT:
67
            return " * ";  //$NON-NLS-1$
68
        case PROPERTIES_COMMENT:
69
            return "# "; //$NON-NLS-1$
70
        default:
71
            return null;
72
        }
73
	}
74
75
	private void writeCommentStart(PrintWriter writer) {
76
	    switch(commentStyle) {
77
	    case JAVA_COMMENT:
78
			writer.println("/*******************************************************************************"); //$NON-NLS-1$
79
			break;
80
	    case PROPERTIES_COMMENT:
81
		    writer.println("###############################################################################"); //$NON-NLS-1$
82
		    break;
83
	    }
84
	}
85
86
	private void writeContributions(PrintWriter writer, String linePrefix) {
87
		writer.println(linePrefix);
88
		writer.println(linePrefix + "Contributors:"); //$NON-NLS-1$
89
90
		if (contributors == null || contributors.size() <= 0)
91
		    writer.println(linePrefix + "    IBM Corporation - initial API and implementation"); //$NON-NLS-1$
92
		else {
93
			Iterator i = contributors.iterator();
94
			while (i.hasNext())
95
			    writer.println(linePrefix + "    " + (String)i.next());  //$NON-NLS-1$
96
		}
97
	}
98
99
	private void writeCommentEnd(PrintWriter writer) {
100
	    switch(commentStyle) {
101
	    case JAVA_COMMENT:
102
			writer.println(" *******************************************************************************/"); //$NON-NLS-1$
103
			break;
104
	    case PROPERTIES_COMMENT:
105
		    writer.println("###############################################################################"); //$NON-NLS-1$
106
		    break;
107
	    }
108
	}
109
	
110
	/**
111
	 * Get the copyright tool preference store
112
	 * @return
113
	 */
114
    private static IPreferenceStore getPreferenceStore() {
115
    	return RelEngPlugin.getDefault().getPreferenceStore();
116
    }
117
	
118
	/**
119
	 * Get the copyright statement in form of an array of Strings where
120
	 * each item is a line of the copyright statement.
121
	 * @return String[]
122
	 */
123
	private static String[] getLegalLines() {
124
		StringTokenizer st = new StringTokenizer(getPreferenceStore().getString(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY), NEW_LINE, true);
125
		ArrayList lines = new ArrayList();
126
		String previous = NEW_LINE;
127
		while (st.hasMoreTokens()) {
128
			String current = st.nextToken();
129
			// add empty lines to array as well
130
			if (NEW_LINE.equals(previous)) {
131
				lines.add(current);
132
			}
133
			previous = current;
134
		}
135
		String[] stringLines = new String[lines.size()];
136
		stringLines = (String[])lines.toArray(stringLines); 
137
		return stringLines;
138
	}
139
	
140
	/**
141
	 * Return the body of this copyright comment or null if it cannot be built.
142
	 */
143
	public String getCopyrightComment() {
144
		// instead of overwriting an existing comment, just try to insert the new year
145
		// disable fix up existing copyright till it works better
146
//		if ((preYearComment != null || postYearComment != null) && (!getPreferenceStore().getBoolean(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY))) {
147
		if ((preYearComment != null || postYearComment != null)) {
148
			String copyrightString = preYearComment == null ? "" : preYearComment; //$NON-NLS-1$
149
			copyrightString = copyrightString + creationYear;
150
			
151
			if (revisionYear != -1 && revisionYear != creationYear)
152
		        copyrightString = copyrightString + ", " + revisionYear; //$NON-NLS-1$
153
			
154
			String endString = postYearComment == null ? "" : postYearComment; //$NON-NLS-1$
155
			copyrightString = copyrightString + endString;
156
			return copyrightString;
157
		}
158
		
159
	    String linePrefix = getLinePrefix(commentStyle);
160
	    if (linePrefix == null)
161
	        return null;
162
163
	    StringWriter out = new StringWriter();
164
		PrintWriter writer = new PrintWriter(out);
165
		try {
166
		    writeCommentStart(writer);
167
			writeLegal(writer, linePrefix);
168
			// dont do anything special with contributors right now
169
//			writeContributions(writer, linePrefix);
170
		    writeCommentEnd(writer);
171
172
			return out.toString();
173
		} finally {
174
		    writer.close();
175
		}
176
	}
177
	
178
	/**
179
	 * Write out the copyright statement, line by line, adding in the created/revision
180
	 * year as well as comment line prefixes.
181
	 * 
182
	 * @param writer
183
	 * @param linePrefix
184
	 */
185
	private void writeLegal(PrintWriter writer, String linePrefix) {
186
		String[] legalLines = getLegalLines();
187
		for (int i=0; i < legalLines.length; ++i) {
188
			String currentLine = legalLines[i];
189
			int offset = currentLine.indexOf(DATE_VAR);
190
			// if this is the line, containing the ${date}, add in the year
191
			if (offset > -1) {
192
				writer.print(linePrefix + currentLine.substring(0, offset)+creationYear);
193
				if (revisionYear != -1 && revisionYear != creationYear)
194
			        writer.print(", " + revisionYear); //$NON-NLS-1$
195
				writer.println(currentLine.substring(offset+DATE_VAR.length(), currentLine.length()));
196
			} else {
197
				// just write out the line
198
				if (NEW_LINE.equals(currentLine)) {
199
					// handle empty lines
200
					writer.print(linePrefix + currentLine);
201
				} else {
202
					writer.println(linePrefix + currentLine);
203
				}
204
			}
205
		}
206
	}
207
	
208
    /**
209
     * Create an instance the same as the argument comment but with the revision year
210
     * updated if needed.  Return the default comment if the argument comment is null
211
     * or an empty string.  Return null if the argument comment is not recognized as
212
     * an IBM copyright comment.
213
     */
214
    public static AdvancedCopyrightComment parse(BlockComment comment, int commentStyle) {
215
    	AdvancedCopyrightComment copyright = null;
216
        
217
    	if (comment == null) {
218
    		copyright = defaultComment(commentStyle);
219
    	} else {
220
    		// To make the comment search a little more flexible, the parse algorithm will 
221
    		// only parse the line containing the ${date}
222
	   	    String body = comment.getContents();
223
	   	    
224
	   	    // find the line with ${date}
225
	   	    String[] legalLines = getLegalLines();
226
	   	    int i = 0;
227
	   	    int yearOffset = -1;
228
	   	    while (i < legalLines.length && yearOffset == -1) {
229
	   	    	String line = legalLines[i];
230
	   	    	yearOffset = line.indexOf(DATE_VAR);
231
	   	    	++i;
232
	   	    }
233
	   	    // ${date} found
234
	   	    if (yearOffset != -1) {
235
	   	    	String yearLine = legalLines[i-1];
236
	   	   	    // split that line up and just search for the contents before and after
237
	   	    	// NOTE: this won't really work well if the text surrounding the year is
238
	   	    	// generic, or if the year is at the beginning or end of the line
239
	   	    	String preYear = yearLine.substring(0, yearOffset);
240
	   	    	String postYear = yearLine.substring(yearOffset+DATE_VAR.length(), yearLine.length());
241
	   	    	
242
	   	    	int preYearOffset = body.indexOf(preYear);
243
	   	    	if (preYearOffset != -1) {
244
	   	    		int postYearOffset = body.indexOf(postYear, preYearOffset);
245
	   	    		if (postYearOffset != -1) {
246
	   	    	   	    // then you know between that is the year
247
	   	    			String yearRange = body.substring(preYearOffset+preYear.length(), postYearOffset);
248
	   	    	   	    int comma = yearRange.indexOf(","); //$NON-NLS-1$
249
	
250
	   	    	   	    String startStr = comma == -1 ? yearRange : yearRange.substring(0, comma);
251
	   	    	   	    String endStr = comma == -1 ? null : yearRange.substring(comma + 1);
252
	
253
	   	    	   	    int startYear = -1;
254
	   	    	   	    if (startStr != null)
255
	   	    		   	    try {
256
	   	    		   	        startYear = Integer.parseInt(startStr.trim());
257
	   	    		   	    } catch(NumberFormatException e) {
258
	   	    		   	        // do nothing
259
	   	    		   	    }
260
	
261
	   	    	   	    int endYear = -1;
262
	   	    	   	    if (endStr != null) {
263
	   	    	   	        try {
264
	   	    	   	            endYear = Integer.parseInt(endStr.trim());
265
	   	    	   	        } catch(NumberFormatException e) {
266
	   	    	   	            // do nothing
267
	   	    	   	        }
268
	   	    	   	    }
269
	   	    	   	    // save the copyright comment's contents before and after the year so that
270
	   	    	   	    // the comment will remain untouched rather than overwritten if the template is
271
	   	    	   	    // almost the same
272
	   	    	   	    String pre = body.substring(0, preYearOffset+preYear.length());
273
	   	    	   	    String post = body.substring(postYearOffset);
274
	   	    	   	     
275
	   	    	   	    copyright = new AdvancedCopyrightComment(commentStyle, startYear, endYear, null, pre, post);
276
	   	    		}
277
	   	    	}
278
	   	    }
279
    	}
280
281
    	// don't do anything special with contributors right now
282
//   	    int contrib = body.indexOf("Contributors:", start); //$NON-NLS-1$
283
//   	    String contribComment = body.substring(contrib);
284
//   	    StringTokenizer tokens = new StringTokenizer(contribComment, "\r\n"); //$NON-NLS-1$
285
//   	    tokens.nextToken();
286
//   	    ArrayList contributors = new ArrayList();
287
//        String linePrefix = getLinePrefix(commentStyle);
288
//   	    while(tokens.hasMoreTokens()) {
289
//   	        String contributor = tokens.nextToken();
290
//   	        if (contributor.indexOf("***********************************") == -1 //$NON-NLS-1$
291
//   	         && contributor.indexOf("###################################") == -1) { //$NON-NLS-1$
292
//   	            int c = contributor.indexOf(linePrefix);
293
//   	            if (c != -1)
294
//   	                contributor = contributor.substring(c + linePrefix.length());
295
//   	            contributors.add(contributor.trim());
296
//   	        }
297
//   	    }
298
//
299
//        return new IBMCopyrightComment(commentStyle, startYear, endYear, contributors);
300
    	return copyright;
301
    }
302
}
(-)src/org/eclipse/releng/tools/AdvancedFixCopyrightAction.java (+391 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tools;
12
13
import java.io.File;
14
import java.io.FileNotFoundException;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
17
import java.util.ArrayList;
18
import java.util.Calendar;
19
import java.util.GregorianCalendar;
20
import java.util.HashMap;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.Set;
25
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IResource;
28
import org.eclipse.core.resources.IResourceVisitor;
29
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.resources.WorkspaceJob;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IAdaptable;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.NullProgressMonitor;
36
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.core.runtime.Status;
38
import org.eclipse.core.runtime.SubProgressMonitor;
39
import org.eclipse.jface.action.IAction;
40
import org.eclipse.jface.preference.IPreferenceStore;
41
import org.eclipse.jface.viewers.ISelection;
42
import org.eclipse.jface.viewers.IStructuredSelection;
43
import org.eclipse.releng.tools.preferences.RelEngCopyrightConstants;
44
import org.eclipse.team.core.TeamException;
45
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
46
import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
47
import org.eclipse.team.internal.ccvs.core.ILogEntry;
48
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
49
import org.eclipse.ui.IActionDelegate;
50
import org.eclipse.ui.IObjectActionDelegate;
51
import org.eclipse.ui.IWorkbenchPart;
52
53
public class AdvancedFixCopyrightAction implements IObjectActionDelegate {
54
55
    public class MyInnerClass implements IResourceVisitor {
56
        public IProgressMonitor monitor;
57
        public boolean visit(IResource resource) throws CoreException {
58
        	if (!monitor.isCanceled()) {
59
	            if (resource.getType() == IResource.FILE) {
60
	                processFile((IFile) resource, monitor);
61
	            }
62
        	}
63
        	return true;
64
        }
65
    }
66
67
    private String propertiesCopyright;
68
    private String javaCopyright;
69
    private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
70
    private Map log = new HashMap();
71
72
    // The current selection
73
    protected IStructuredSelection selection;
74
75
    private static final int currentYear = new GregorianCalendar().get(Calendar.YEAR);
76
77
    /**
78
     * Constructor for Action1.
79
     */
80
    public AdvancedFixCopyrightAction() {
81
        super();
82
    }
83
84
    /**
85
     * Returns the selected resources.
86
     * 
87
     * @return the selected resources
88
     */
89
    protected IResource[] getSelectedResources() {
90
        ArrayList resources = null;
91
        if (!selection.isEmpty()) {
92
            resources = new ArrayList();
93
            Iterator elements = selection.iterator();
94
            while (elements.hasNext()) {
95
                Object next = elements.next();
96
                if (next instanceof IResource) {
97
                    resources.add(next);
98
                    continue;
99
                }
100
                if (next instanceof IAdaptable) {
101
                    IAdaptable a = (IAdaptable) next;
102
                    Object adapter = a.getAdapter(IResource.class);
103
                    if (adapter instanceof IResource) {
104
                        resources.add(adapter);
105
                        continue;
106
                    }
107
                }
108
            }
109
        }
110
        if (resources != null && !resources.isEmpty()) {
111
            IResource[] result = new IResource[resources.size()];
112
            resources.toArray(result);
113
            return result;
114
        }
115
        return new IResource[0];
116
    }
117
118
    /**
119
     * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
120
     */
121
    public void setActivePart(IAction action, IWorkbenchPart targetPart) {
122
    }
123
124
    /**
125
     * @see IActionDelegate#run(IAction)
126
     */
127
    public void run(IAction action) {
128
        log = new HashMap();
129
    	WorkspaceJob wJob = new WorkspaceJob("Fixing copyrights") {	//$NON-NLS-1$
130
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
131
                try {
132
                	long start = System.currentTimeMillis();
133
                    System.out.println("Start Fixing Copyrights"); //$NON-NLS-1$
134
                    IResource[] results = getSelectedResources();
135
                    System.out.println("Resources selected: " //$NON-NLS-1$
136
                            + results.length);
137
                    monitor.beginTask("Fixing copyrights...", //$NON-NLS-1$
138
                            results.length);
139
140
                    for (int i = 0; i < results.length; i++) {
141
                        IResource resource = results[i];
142
                        System.out.println(resource.getName());
143
                        try {
144
                            MyInnerClass myInnerClass = new MyInnerClass();
145
                            myInnerClass.monitor = monitor;
146
                            resource.accept(myInnerClass);
147
                            
148
                            monitor.worked(1);
149
                        } catch (CoreException e1) {
150
                            e1.printStackTrace();
151
                        }
152
                    }
153
154
                    writeLogs();
155
               		displayLogs();
156
                    System.out.println("Done Fixing Copyrights"); //$NON-NLS-1$
157
                    long end = System.currentTimeMillis();
158
                    System.out.println("Total time: "+(end-start)+"ms"); //$NON-NLS-1$ //$NON-NLS-2$
159
160
                } finally {
161
                    monitor.done();
162
                }
163
				return Status.OK_STATUS;
164
			}
165
    	};
166
    	
167
    	wJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
168
    	wJob.setUser(true);
169
    	wJob.schedule();
170
//          try {
171
//            PlatformUI.getWorkbench().getProgressService().run(true, /* fork */
172
//            true, /* cancellable */
173
//            new IRunnableWithProgress() {
174
//
175
//                public void run(IProgressMonitor monitor)
176
//                        throws InvocationTargetException, InterruptedException {
177
//                    try {
178
//                    	long start = System.currentTimeMillis();
179
//                        monitor.beginTask("Fixing copyrights...", //$NON-NLS-1$
180
//                                IProgressMonitor.UNKNOWN);
181
//
182
//                        System.out.println("Start Fixing Copyrights"); //$NON-NLS-1$
183
//                        IResource[] results = getSelectedResources();
184
//                        System.out.println("Resources selected: " //$NON-NLS-1$
185
//                                + results.length);
186
//                        for (int i = 0; i < results.length; i++) {
187
//                            IResource resource = results[i];
188
//                            System.out.println(resource.getName());
189
//                            try {
190
//                                MyInnerClass myInnerClass = new MyInnerClass();
191
//                                myInnerClass.monitor = monitor;
192
//                                resource.accept(myInnerClass);
193
//                            } catch (CoreException e1) {
194
//                                e1.printStackTrace();
195
//                            }
196
//                        }
197
//
198
//                        writeLogs();
199
//                   		displayLogs();
200
//                        System.out.println("Done Fixing Copyrights"); //$NON-NLS-1$
201
//                        long end = System.currentTimeMillis();
202
//                        System.out.println("Total time: "+(end-start)+"ms"); //$NON-NLS-1$ //$NON-NLS-2$
203
//
204
//                    } finally {
205
//                        monitor.done();
206
//                    }
207
//                }
208
//            });
209
//        } catch (InvocationTargetException e) {
210
//            // TODO Auto-generated catch block
211
//            e.printStackTrace();
212
//        } catch (InterruptedException e) {
213
//            // TODO Auto-generated catch block
214
//            e.printStackTrace();
215
//        }
216
    }
217
218
    /**
219
     * Lookup and return the year in which the argument file was revised.  Return -1 if
220
     * the revision year cannot be found.
221
     */
222
    private int getCVSModificationYear(IFile file, IProgressMonitor monitor) {
223
        try {
224
            monitor.beginTask("Fetching logs from CVS", 100); //$NON-NLS-1$
225
226
            try {
227
                ICVSRemoteResource cvsFile = CVSWorkspaceRoot.getRemoteResourceFor(file);
228
                if (cvsFile != null) {
229
	                // get the log entry for the revision loaded in the workspace
230
	                ILogEntry entry = ((ICVSRemoteFile)cvsFile)
231
	                        .getLogEntry(new SubProgressMonitor(monitor, 100));
232
	                return entry.getDate().getYear() + 1900;
233
                }
234
            } catch (TeamException e) {
235
                // do nothing
236
            }
237
        } finally {
238
            monitor.done();
239
        }
240
241
        return -1;
242
    }
243
244
    /**
245
     *  
246
     */
247
    private void writeLogs() {
248
249
        FileOutputStream aStream;
250
        try {
251
            File aFile = new File(Platform.getLocation().toFile(),
252
                    "copyrightLog.txt"); //$NON-NLS-1$
253
            aStream = new FileOutputStream(aFile);
254
            Set aSet = log.entrySet();
255
            Iterator errorIterator = aSet.iterator();
256
            while (errorIterator.hasNext()) {
257
                Map.Entry anEntry = (Map.Entry) errorIterator.next();
258
                String errorDescription = (String) anEntry.getKey();
259
                aStream.write(errorDescription.getBytes());
260
                aStream.write(newLine.getBytes());
261
                List fileList = (List) anEntry.getValue();
262
                Iterator listIterator = fileList.iterator();
263
                while (listIterator.hasNext()) {
264
                    String fileName = (String) listIterator.next();
265
                    aStream.write("     ".getBytes()); //$NON-NLS-1$
266
                    aStream.write(fileName.getBytes());
267
                    aStream.write(newLine.getBytes());
268
                }
269
            }
270
            aStream.close();
271
        } catch (FileNotFoundException e) {
272
            e.printStackTrace();
273
        } catch (IOException e) {
274
            e.printStackTrace();
275
        }
276
    }
277
278
    private void displayLogs() {
279
280
        Set aSet = log.entrySet();
281
        Iterator errorIterator = aSet.iterator();
282
        while (errorIterator.hasNext()) {
283
            Map.Entry anEntry = (Map.Entry) errorIterator.next();
284
            String errorDescription = (String) anEntry.getKey();
285
            System.out.println(errorDescription);
286
            List fileList = (List) anEntry.getValue();
287
            Iterator listIterator = fileList.iterator();
288
            while (listIterator.hasNext()) {
289
                String fileName = (String) listIterator.next();
290
                System.out.println("     " + fileName); //$NON-NLS-1$
291
            }
292
        }
293
    }
294
295
    /**
296
     * @param file
297
     */
298
    private void processFile(IFile file, IProgressMonitor monitor) {
299
        SourceFile aSourceFile;
300
301
        String extension = file.getFileExtension();
302
        if (extension == null)
303
            return;
304
        monitor.subTask(file.getFullPath().toOSString());
305
        int fileType = AdvancedCopyrightComment.UNKNOWN_COMMENT;
306
        extension = extension.toLowerCase();
307
        if (extension.equals("java")) { //$NON-NLS-1$
308
        	fileType = AdvancedCopyrightComment.JAVA_COMMENT;
309
            aSourceFile = new JavaFile(file);
310
        } else if (extension.equals("properties")) { //$NON-NLS-1$
311
        	// if stop processing if ignoring properties files
312
        	if (RelEngPlugin.getDefault().getPreferenceStore().getBoolean(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY)) {
313
        		return;
314
        	}
315
        	fileType = AdvancedCopyrightComment.PROPERTIES_COMMENT;
316
            aSourceFile = new PropertiesFile(file);
317
        } else
318
            return;
319
320
        if (aSourceFile.hasMultipleCopyrights()) {
321
            warn(file, null, "Multiple copyrights found.  File UNCHANGED."); //$NON-NLS-1$//$NON-NLS-2$
322
            return;
323
        }
324
325
        IPreferenceStore prefStore = RelEngPlugin.getDefault().getPreferenceStore();
326
        BlockComment copyrightComment = aSourceFile.firstCopyrightComment();
327
        AdvancedCopyrightComment ibmCopyright = null;
328
        // if replacing all comments, dont even parse, just use default copyright comment
329
    	if (prefStore.getBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY)) {
330
    		ibmCopyright = AdvancedCopyrightComment.defaultComment(fileType);
331
    	} else {
332
            ibmCopyright = AdvancedCopyrightComment.parse(copyrightComment, fileType);    		
333
    	}
334
335
        if (ibmCopyright == null) {
336
        	warn(file, copyrightComment, "Could not interpret copyright comment"); //$NON-NLS-1$
337
        	return;
338
        }
339
340
        // figure out revision year
341
        int revised = ibmCopyright.getRevisionYear();
342
        int lastMod = revised;
343
        if (prefStore.getBoolean(RelEngCopyrightConstants.USE_DEFAULT_REVISION_YEAR_KEY))
344
        	lastMod = prefStore.getInt(RelEngCopyrightConstants.REVISION_YEAR_KEY);
345
        else {
346
            // figure out if the comment should be updated by comparing the date range
347
            // in the comment to the last modification time provided by CVS
348
	        if (lastMod < currentYear) {
349
	            lastMod = getCVSModificationYear(file, new NullProgressMonitor());
350
	            // use default revision year
351
	            if (lastMod == -1)
352
	            	lastMod = prefStore.getInt(RelEngCopyrightConstants.REVISION_YEAR_KEY);
353
	        }
354
        }
355
356
        // only exit if existing copyright comment already contains the year
357
        // of last modification and not overwriting all comments
358
        if (lastMod <= revised && (copyrightComment != null) && (!prefStore.getBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY)))
359
            return;
360
361
        // either replace old copyright or put the new one at the top of the file
362
        ibmCopyright.setRevisionYear(lastMod);
363
        if (copyrightComment == null)
364
            aSourceFile.insert(ibmCopyright.getCopyrightComment());
365
        else {
366
            if (!copyrightComment.atTop())
367
                warn(file, copyrightComment, "Old copyright not at start of file, new copyright replaces old in same location"); //$NON-NLS-1$
368
            aSourceFile.replace(copyrightComment, ibmCopyright.getCopyrightComment());
369
        }
370
    }
371
372
    private void warn(IFile file, BlockComment firstBlockComment,
373
            String errorDescription) {
374
        List aList = (List) log.get(errorDescription);
375
        if (aList == null) {
376
            aList = new ArrayList();
377
            log.put(errorDescription, aList);
378
        }
379
        aList.add(file.getName());
380
    }
381
382
    /**
383
     * @see IActionDelegate#selectionChanged(IAction, ISelection)
384
     */
385
    public void selectionChanged(IAction action, ISelection selection) {
386
        if (selection instanceof IStructuredSelection) {
387
            this.selection = (IStructuredSelection) selection;
388
        }
389
    }
390
391
}
(-)src/org/eclipse/releng/tools/preferences/CopyrightPreferencePage.java (+367 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tools.preferences;
12
13
import org.eclipse.jface.preference.IPreferenceStore;
14
import org.eclipse.jface.preference.PreferencePage;
15
import org.eclipse.jface.text.BadLocationException;
16
import org.eclipse.jface.text.Document;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.text.source.SourceViewer;
20
import org.eclipse.jface.text.source.SourceViewerConfiguration;
21
import org.eclipse.releng.tools.Messages;
22
import org.eclipse.releng.tools.RelEngPlugin;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.KeyAdapter;
25
import org.eclipse.swt.events.KeyEvent;
26
import org.eclipse.swt.events.KeyListener;
27
import org.eclipse.swt.graphics.Font;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.Button;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.swt.widgets.Text;
35
import org.eclipse.ui.IWorkbench;
36
import org.eclipse.ui.IWorkbenchPreferencePage;
37
38
/**
39
 * Copyright tools preference page
40
 */
41
public class CopyrightPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
42
	private final String NEW_LINE = "\n"; //$NON-NLS-1$
43
	private Composite fComposite;
44
	private Label fCopyrightLabel;
45
	private SourceViewer fEditor;
46
	private Text fInstructions;
47
	private Label fCreationYearLabel;
48
	private Text fCreationYear;
49
	private Label fRevisionYearLabel;
50
	private Text fRevisionYear;
51
	private Button fUseDefaultRevisionYear;
52
	private Button fReplaceAllExisting;
53
	// disable fix up existing copyright till it works better
54
//	private Button fFixExisting;
55
	private Button fIgnoreProperties;
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
59
	 */
60
	public void init(IWorkbench workbench) {
61
		// TODO Auto-generated method stub
62
63
	}
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
66
	 */
67
	protected Control createContents(Composite parent) {
68
		Font font = parent.getFont();
69
70
		//The main composite
71
		fComposite = new Composite(parent, SWT.NONE);
72
		GridLayout layout = new GridLayout();
73
		layout.numColumns = 2;
74
		layout.marginWidth = 0;
75
		layout.marginHeight = 0;
76
		fComposite.setLayout(layout);
77
		fComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
78
		fComposite.setFont(font);
79
80
		// copyright template editor
81
		fEditor = createEditor(fComposite);
82
		
83
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
84
		data.horizontalSpan = 2;
85
		data.horizontalIndent = 0;
86
		fInstructions = new Text(fComposite, SWT.READ_ONLY);
87
		fInstructions.setText(Messages.getString("CopyrightPreferencePage.0")); //$NON-NLS-1$
88
		fInstructions.setLayoutData(data);
89
		
90
		// default creation year
91
		fCreationYearLabel = new Label(fComposite, SWT.NONE);
92
		fCreationYearLabel.setText(Messages.getString("CopyrightPreferencePage.1")); //$NON-NLS-1$
93
		fCreationYear = new Text(fComposite, SWT.BORDER);
94
		fCreationYear.setTextLimit(4);
95
		
96
		// default revision year
97
		fRevisionYearLabel = new Label(fComposite, SWT.NONE);
98
		fRevisionYearLabel.setText(Messages.getString("CopyrightPreferencePage.7")); //$NON-NLS-1$
99
		fRevisionYear = new Text(fComposite, SWT.BORDER);
100
		fRevisionYear.setTextLimit(4);
101
		
102
		// always use default revision year instead of cvs lookup
103
		fUseDefaultRevisionYear = new Button(fComposite, SWT.CHECK);
104
		fUseDefaultRevisionYear.setText(Messages.getString("CopyrightPreferencePage.8")); //$NON-NLS-1$
105
		data = new GridData();
106
		data.horizontalSpan = 2;
107
		fUseDefaultRevisionYear.setLayoutData(data);
108
		
109
		// replace all existing copyright statement
110
		fReplaceAllExisting = new Button(fComposite, SWT.CHECK);
111
		fReplaceAllExisting.setText(Messages.getString("CopyrightPreferencePage.2")); //$NON-NLS-1$
112
		data = new GridData();
113
		data.horizontalSpan = 2;
114
		fReplaceAllExisting.setLayoutData(data);
115
		
116
		// disable fix up existing copyright till it works better
117
//		// fix up existing copyright statement
118
//		fFixExisting = new Button(fComposite, SWT.CHECK);
119
//		fFixExisting.setText(Messages.getString("CopyrightPreferencePage.3")); //$NON-NLS-1$
120
//		data = new GridData();
121
//		data.horizontalSpan = 2;
122
//		fFixExisting.setLayoutData(data);
123
		
124
		// ignore properties files
125
		fIgnoreProperties = new Button(fComposite, SWT.CHECK);
126
		fIgnoreProperties.setText(Messages.getString("CopyrightPreferencePage.4")); //$NON-NLS-1$
127
		data = new GridData();
128
		data.horizontalSpan = 2;
129
		fIgnoreProperties.setLayoutData(data);
130
		
131
		KeyListener listener1 = new KeyAdapter() {
132
			/* (non-Javadoc)
133
			 * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
134
			 */
135
			public void keyReleased(KeyEvent e) {
136
				validateValues();
137
			}
138
		};
139
		fCreationYear.addKeyListener(listener1);
140
		fRevisionYear.addKeyListener(listener1);
141
		
142
		// disable fix up existing copyright till it works better
143
//		SelectionListener listener2 = new SelectionAdapter() {
144
//			public void widgetSelected(SelectionEvent e) {
145
//				handleReplaceAllEnabled(fReplaceAllExisting.getSelection(), fFixExisting.getSelection());
146
//			}
147
//		};
148
//		fReplaceAllExisting.addSelectionListener(listener2);
149
		
150
		initializeValues();
151
		return fComposite;
152
	}
153
154
	/**
155
	 * Create the sourceviewer editor to be used to edit the copyright template
156
	 */
157
	private SourceViewer createEditor(Composite parent) {
158
		fCopyrightLabel = new Label(parent, SWT.NONE);
159
		fCopyrightLabel.setText(Messages.getString("CopyrightPreferencePage.5")); //$NON-NLS-1$
160
		GridData data= new GridData();
161
		data.horizontalSpan= 2;
162
		fCopyrightLabel.setLayoutData(data);
163
		
164
		SourceViewer viewer= createViewer(parent);
165
166
		IDocument document= new Document();
167
		viewer.setEditable(true);
168
		viewer.setDocument(document);
169
		
170
		// just use a default 10 lines
171
		int nLines = 10;
172
//		int nLines= document.getNumberOfLines();
173
//		if (nLines < 5) {
174
//			nLines= 5;
175
//		} else if (nLines > 12) {
176
//			nLines= 12;	
177
//		}
178
				
179
		Control control= viewer.getControl();
180
		data= new GridData(GridData.FILL_HORIZONTAL);
181
		data.widthHint= convertWidthInCharsToPixels(80);
182
		data.heightHint= convertHeightInCharsToPixels(nLines);
183
		data.horizontalSpan = 2;
184
		control.setLayoutData(data);
185
		
186
		// TODO add content assist support
187
//		viewer.addTextListener(new ITextListener() {
188
//			public void textChanged(TextEvent event) {
189
//				if (event.getDocumentEvent() != null)
190
//					doSourceChanged(event.getDocumentEvent().getDocument());
191
//			}
192
//		});
193
//
194
//		viewer.addSelectionChangedListener(new ISelectionChangedListener() {			
195
//			public void selectionChanged(SelectionChangedEvent event) {
196
//				updateSelectionDependentActions();
197
//			}
198
//		});
199
//
200
//	 	viewer.prependVerifyKeyListener(new VerifyKeyListener() {
201
//			public void verifyKey(VerifyEvent event) {
202
//				handleVerifyKeyPressed(event);
203
//			}
204
//		});
205
		
206
		return viewer;
207
	}
208
	
209
	/**
210
	 * Creates the viewer to be used to display the copyright.
211
	 * 
212
	 * @param parent the parent composite of the viewer
213
	 * @return a configured <code>SourceViewer</code>
214
	 */
215
	private SourceViewer createViewer(Composite parent) {
216
		SourceViewer viewer= new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
217
		SourceViewerConfiguration configuration= new SourceViewerConfiguration() {
218
			// TODO add content assist support
219
//			public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
220
//				
221
//				ContentAssistant assistant= new ContentAssistant();
222
//				assistant.enableAutoActivation(true);
223
//				assistant.enableAutoInsert(true);
224
//				assistant.setContentAssistProcessor(fTemplateProcessor, IDocument.DEFAULT_CONTENT_TYPE);
225
//				return assistant;
226
//			}
227
		};
228
		viewer.configure(configuration);
229
		return viewer;
230
	}
231
	
232
	/**
233
	 * Initialize the control values in this preference page
234
	 */
235
	private void initializeValues() {
236
		IPreferenceStore store = getPreferenceStore();
237
238
		fEditor.getDocument().set(store.getString(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY));
239
		fCreationYear.setText(store.getString(RelEngCopyrightConstants.CREATION_YEAR_KEY));
240
		fRevisionYear.setText(store.getString(RelEngCopyrightConstants.REVISION_YEAR_KEY));
241
		fUseDefaultRevisionYear.setSelection(store.getBoolean(RelEngCopyrightConstants.USE_DEFAULT_REVISION_YEAR_KEY));
242
		fReplaceAllExisting.setSelection(store.getBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY));
243
		// disable fix up existing copyright till it works better
244
//		handleReplaceAllEnabled(fReplaceAllExisting.getSelection(), store.getBoolean(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY));
245
		fIgnoreProperties.setSelection(store.getBoolean(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY));		
246
	}
247
	
248
	/**
249
	 * Validate the control values in this preference page
250
	 */
251
	private void validateValues() {
252
		String ERROR_MESSAGE = Messages.getString("CopyrightPreferencePage.6"); //$NON-NLS-1$
253
		
254
		String errorMsg = null;
255
		
256
		// creation & revision year must be an integer
257
		String creationYear = fCreationYear.getText();
258
		String revisionYear = fRevisionYear.getText();
259
		try {
260
			int year = Integer.parseInt(creationYear);
261
			if (year < 0) {
262
				errorMsg = ERROR_MESSAGE;
263
			}
264
			year = Integer.parseInt(revisionYear);
265
			if (year < 0) {
266
				errorMsg = ERROR_MESSAGE;
267
			}
268
		} catch (NumberFormatException e) {
269
			errorMsg = ERROR_MESSAGE;
270
		}
271
		setErrorMessage(errorMsg);
272
		setValid(errorMsg == null);
273
	}
274
	
275
	// disable fix up existing copyright till it works better
276
//	/**
277
//	 * Handles when the Replace all copyrights checkbox is checked/unchecked.
278
//	 * When checked, fix up copyright checkbox is disabled and checked
279
//	 * When unchecked, fix up copyright checkbox is enabled and set to default value 
280
//	 * @param replaceAll
281
//	 * @param defaultValue
282
//	 */
283
//	private void handleReplaceAllEnabled(boolean replaceAll, boolean defaultValue) {
284
//		if (fReplaceAllExisting.isEnabled() && !replaceAll)
285
//			fFixExisting.setEnabled(true);
286
//		else
287
//			fFixExisting.setEnabled(false);
288
//		
289
//		if (replaceAll) {
290
//			fFixExisting.setSelection(replaceAll);
291
//		} else {
292
//			fFixExisting.setSelection(defaultValue);
293
//		}
294
//	}
295
296
	/* (non-Javadoc)
297
	 * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore()
298
	 */
299
	protected IPreferenceStore doGetPreferenceStore() {
300
		return RelEngPlugin.getDefault().getPreferenceStore();
301
	}
302
303
	/* (non-Javadoc)
304
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
305
	 */
306
	protected void performDefaults() {
307
		IPreferenceStore store = getPreferenceStore();
308
		
309
		fEditor.getDocument().set(store.getDefaultString(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY));
310
		fCreationYear.setText(store.getDefaultString(RelEngCopyrightConstants.CREATION_YEAR_KEY));
311
		fRevisionYear.setText(store.getDefaultString(RelEngCopyrightConstants.REVISION_YEAR_KEY));
312
		fUseDefaultRevisionYear.setSelection(getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.USE_DEFAULT_REVISION_YEAR_KEY));
313
		fReplaceAllExisting.setSelection(getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY));
314
		// disable fix up existing copyright till it works better
315
//		handleReplaceAllEnabled(fReplaceAllExisting.getSelection(), getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY));
316
		fIgnoreProperties.setSelection(getPreferenceStore().getDefaultBoolean(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY));
317
		
318
		super.performDefaults();
319
	}
320
	
321
	/* (non-Javadoc)
322
	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
323
	 */
324
	public boolean performOk() {
325
		IPreferenceStore store = getPreferenceStore();
326
327
		store.setValue(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY, fixupLineDelimiters(fEditor.getDocument()));
328
		store.setValue(RelEngCopyrightConstants.CREATION_YEAR_KEY, fCreationYear.getText());
329
		store.setValue(RelEngCopyrightConstants.REVISION_YEAR_KEY, fRevisionYear.getText());
330
		store.setValue(RelEngCopyrightConstants.USE_DEFAULT_REVISION_YEAR_KEY, fUseDefaultRevisionYear.getSelection());
331
		store.setValue(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY, fReplaceAllExisting.getSelection());
332
		// disable fix up existing copyright till it works better
333
//		store.setValue(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY, fFixExisting.getSelection());
334
		store.setValue(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY, fIgnoreProperties.getSelection());
335
		
336
		RelEngPlugin.getDefault().savePluginPreferences();
337
		
338
		return super.performOk();
339
	}
340
	
341
	/**
342
	 * Fix up line delimiters in doc to use only \n
343
	 * @param doc
344
	 * @return
345
	 */
346
	private String fixupLineDelimiters(IDocument doc) {
347
		String docContents = doc.get();
348
		String newText = ""; //$NON-NLS-1$
349
		int lineCount = doc.getNumberOfLines();
350
		for (int i = 0; i < lineCount; i++) {
351
			try {
352
				IRegion lineInfo = doc.getLineInformation(i);
353
				int lineStartOffset = lineInfo.getOffset();
354
				int lineLength = lineInfo.getLength();
355
				int lineEndOffset = lineStartOffset + lineLength;
356
				newText += docContents.substring(lineStartOffset, lineEndOffset);
357
358
				if ((i < lineCount - 1) && (fEditor.getDocument().getLineDelimiter(i) != null))
359
					newText += NEW_LINE;
360
			}
361
			catch (BadLocationException exception) {
362
				// exception
363
			}
364
		}
365
		return newText;
366
	}
367
}
(-)src/org/eclipse/releng/tools/preferences/RelEngCopyrightConstants.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tools.preferences;
12
13
/**
14
 * Contains all the constants used by the releng copyright tool
15
 */
16
public class RelEngCopyrightConstants {
17
	public final static String COPYRIGHT_TEMPLATE_KEY = "org.eclipse.releng.tools.copyrightTemplate"; //$NON-NLS-1$
18
	public final static String CREATION_YEAR_KEY = "org.eclipse.releng.tools.creationYear"; //$NON-NLS-1$
19
	public final static String REVISION_YEAR_KEY = "org.eclipse.releng.tools.revisionYear"; //$NON-NLS-1$
20
	public final static String USE_DEFAULT_REVISION_YEAR_KEY = "org.eclipse.releng.tools.useDefaultRevisionYear"; //$NON-NLS-1$
21
	// disable fix up existing copyright till it works better
22
//	public final static String FIX_UP_EXISTING_KEY = "org.eclipse.releng.tools.fixUpExisting"; //$NON-NLS-1$
23
	public final static String REPLACE_ALL_EXISTING_KEY = "org.eclipse.releng.tools.replaceAllExisting"; //$NON-NLS-1$
24
	public final static String IGNORE_PROPERTIES_KEY = "org.eclipse.releng.tools.ignoreProperties"; //$NON-NLS-1$
25
}
(-)src/org/eclipse/releng/tools/preferences/RelEngPreferenceInitializer.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tools.preferences;
12
13
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
14
import org.eclipse.jface.preference.IPreferenceStore;
15
import org.eclipse.releng.tools.Messages;
16
import org.eclipse.releng.tools.RelEngPlugin;
17
18
/**
19
 * Initializes default preferences for release engineering tool
20
 */
21
public class RelEngPreferenceInitializer extends AbstractPreferenceInitializer {
22
	private final String LEGAL_LINE = Messages.getString("RelEngPreferenceInitializer.0"); //$NON-NLS-1$
23
	
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
26
	 */
27
	public void initializeDefaultPreferences() {
28
        IPreferenceStore store = RelEngPlugin.getDefault().getPreferenceStore();
29
        store.setDefault(RelEngCopyrightConstants.COPYRIGHT_TEMPLATE_KEY, LEGAL_LINE);
30
        store.setDefault(RelEngCopyrightConstants.CREATION_YEAR_KEY, 2001);
31
        store.setDefault(RelEngCopyrightConstants.REVISION_YEAR_KEY, 2004);
32
        store.setDefault(RelEngCopyrightConstants.USE_DEFAULT_REVISION_YEAR_KEY, false);
33
    	// disable fix up existing copyright till it works better
34
//        store.setDefault(RelEngCopyrightConstants.FIX_UP_EXISTING_KEY, false);
35
        store.setDefault(RelEngCopyrightConstants.REPLACE_ALL_EXISTING_KEY, false);
36
        store.setDefault(RelEngCopyrightConstants.IGNORE_PROPERTIES_KEY, false);
37
	}
38
39
}

Return to bug 77026