URLs

Do you want to improve this page? Please edit it on GitHub.

Current version: 1.5.2

Description

Fork of the Eclipse Copyright Generator project on sourceforge.

Initial work by Eric Wuillai. Contributors: Jeremie Bresson, Matthew Krupcale.

Installation

Use the P2 Repository hosted on Bintray:

https://dl.bintray.com/jmini/Eclipse-Copyright-Generator/

In your Eclipse IDE, just select Help ▸ Install New Software…​. Enter the P2 Update Site URL in the Work with field and select the Copyright Wizard in the list.

Install New Software windows

Usage

The wizard is launched from the menu: Project → Copyright Wizard…​

Apply copyright menu
First page - Projects selection

The first page of the wizard lets you select one or more projects on which to apply the copyright.

Wizard Step 1
Parameter Description

Projects selection list

Projects having copyright settings are marked in the selection list by a "(C)" postfix on the projet name.

Override projects copyright settings

If checked, all projects copyright settings (headers text and formats) defined on selected projects will be override by the settings defined in the following page of the wizard.

Override only the header comment text

This checkbox is enabled only if the previous one is checked. If checked, the override of project copyright settings is limited to the header comment text. All the header formats defined in the projects preferences will be used by the wizard for the corresponding projects.

The second page of the wizard lets you define the parameters of copyright to be applied to the selected projects. It is possible to define a completely specific copyright, or select a preconfigured copyright in the preferences of the wizard.

Wizard Step 2
Parameter Description

Copyright type

Selection list of copyright to apply. This list allows you to select one of the preconfigured copyrights in the preferences, or to choose the definition of a specific copyright (--- Custom copyright ---).

guide04

Copyright header text

Text of comment header to be applied to the selected files. This field is pre-initialized with the text defined in preferences for the selected copyright. It may, however, be changed if desired.

guide05

The text should not contain formatting comment characters.

Include files

Pattern of filenames on which apply the comment header. If leaved empty, it is equivalent to "*" and all resources will be selected. It is possible to give several patterns, separated by commas. Then all resources corresponding at least to one of the patterns will be selected.

guide06

Exclude files

Pattern of filenames to exclude from the selection defined by the include pattern. If leaved empty, there is no exclusion. It is possible to give several patterns, separated by commas. Then all resources corresponding at least to one of the patterns will be excluded.

guide11

Replace existing headers

This flag is used to indicate whether the wizard will replace the existing header files (checked) or if they should not be modified (unchecked). The recognition of the existence of a header comment in a file is made by comparing the 5 first characters in the first line of the file (or the second one if the parameter "Do not override the first line" is checked in the corresponding format) with the 5 first characters of the first line defined in the header comment format.

Add license file if not exists

This flag allows you to add to selected projects a license file if no file with the same name already exists. This parameter is usable only for preconfigured copyrights having a license file defined.

License file

Name and path of the license file to create. This parameter is used only if the previous parameter has been selected. It is initialized by the file name defined in preferences settings for the selected copyright.

Third page - Files selection

The wizard filters with the files patterns the files on which to apply the comment header. If the "Replace existing headers" has been checked, the files containing already a comment header are eligible for treatment. Otherwise they are also excluded from the pre-selection.

The last page of the wizard enables you to refine the selection. It presents the files filtered by the wizard.

Wizard Step 3

The user has the possibility to unselect files or directories on which apply the comment header. In the previous screenshot, files config.properties and Sample2.java were unselected and will therefore not be treated.

Finally click on Finish to start treatment on the selected files.

Example Java file before treatment:

guide09

Example Java file after treatment:

guide10

Copyright settings can be defined at the level of each project too, in the project properties. When defined, those settings are applied by default by the copyright wizard.

To define project settings, open the project properties dialog and select the Copyright category. The properties page displayed contains two tabs.

guide20

Copyright settings are disabled by default. To enable, select the 'Enable project specific settings' checkbox. When enabled, a popup message is displayed proposing to import in the project settings the header formats definitions of the workspace. If you respond No, you will have to define all the header format, including the root Text content type.

guide21

When project settings are selected, the two tabs are enabled:

  • Header text- The first tab allows one to define the header text that will be used by default for all the files in the project on which the wizard will apply a copyright. The same substitution variables that are in workspace preferences can be used here.

  • Header formats- The second tab allows one to define the header comment format for all the content types deriving of the root Text type. This tab works exactly as the workspace preferences one.

The project copyright settings are saved in a file stored in the .settings directory of the project. Then this file can be saved in a SCM tool like CVS or Subversion and shared by a team.

The Copyright parameters allows one to define a set of standard licenses, including the text to be placed in the comment header of files, as well as a license file to add to the projects.

config02
Parameter Description

Owner

Sets the value of the substitution variable ${owner}. If not defined, it will take by default the same value that ${user} variable.

Licenses

List of pre-configured licenses. Selecting an item on this list updates the fields in tabs.

Header text

Tab to define the text of the comment to be placed in the header of files. This text may contain substitution variables, which will be replaced by their values at the time of insertion of the comment in each target file. The text of the comment is defined line by line. It should not contain comment format characters specific to a file type (eg. /* */).

The usable substitution variables are:

${owner} - Value of the owner parameter

${user} - The OS user name

${year} - The current year

${file_name} - Name of the file on which the header is applied

${file_absolute_path} - Absolute path of the file on which the header is applied

${file_path} - Path of the file on which the header is applied, relative to the project root

${project_name} - Name of the project containing the file on which the header is applied

License file

Tab to set the (optional) license file to add to the projects.

The License file tab allows you to associate a license file to a copyright definition:

config03

Parameter Description

File name

Default name of the license file. The file name may be changed if desired by the user within the parameters of the wizard.

File content

Text of the license. If the wanted file format is formatted, such as HTML, the text must contain all the formatting tags. The contents of the file is not interpreted, so the substitution variables do not apply here.

The plugin is preconfigured with headers and licenses files for several open source licenses: Apache, Boost, BSD, (A)GPL, LGPL, MIT, and Mozilla. It is possible to add, change or delete any copyrights with the buttons Add, Modify, and Delete:

  • Add - Add a new Copyright. A dialog box opens for the input of the label text under which the Copyright will be registered.

    config04

  • Modify - Changing the label text of the copyright selected from the list.

  • Delete - Remove the copyright selected from the list.

The 'Restore Defaults' button will reload the default copyrights configuration file provided with the plug-in. All custom texts and copyrights will be lost.

Headers formats preference page

The Header formats parameters are used to define the applicable format of comment on headers for different types of files. The recognition of the type of file is based on the Eclipse ContentType.

The formats apply only on the content in text format. If a format is not set on a ContentType, it inherits the format of its parent, and so on recursively until basic type Text.

config05

To define a particular format on a file type, select the correspondent ContentType in the tree, and enter the definition of the format:

Parameter Description

Exclude this type from copyrights

If checked, all files defined by this ContentType will be automatically excluded by the wizard and will not have a copyright header. All other fields are then disabled.

First line

Format of the first line of the comment header. Typically this line contains no text and is composed of characters to draw a dividing line.

Line prefix

Format for the beginning of a comment line. This string will be placed by concatenation before all the lines of comment text defined in a text of copyrigt header, including blank lines.

Last line

Format of the last line of the comment header. Typically this line contains no text and is composed of characters to draw a dividing line.

Line format comment

Flag indicating if the comment header is in line format (checked) or block format (unchecked). For a comment in line format, it is important to define a valid "Line prefix" for the target language.

Do not override the first line

Flag indicating whether, when inserting a comment in a file of the selected type, the comment must begin on the first line (unchecked) or on the second line (checked).

Some languages require an instruction or a comment of a particular format on the first line of a source file. When checked, the content of the first line will be preserved by the wizard.

First line pattern

Regular expression pattern to apply on the first line. If the line matches, the comment is inserted after the line, otherwise it is inserted before. This pattern is optional. If it is left empty, the first line is always skipped before to insert the comment header.

The regular expression must respect the syntax defined by the Pattern java class.

The labels to the right of the text entry fields indicate the length of the current content of the fields. These labels are particularly useful for long lines and lines containing spaces at the end.

The Clear button erases completely the format definition of the selected ContentType. It then inherits the format of its parent.

The 'Restore Defaults' button will reload the default formats definitions provided with the plug-in. All custom formats will be lost. By default the plug-in defines formats for 'Text', 'C Source File', 'C Header File' , 'C++ Source File' 'C++ Header File', 'Java Source File' and 'XML' content types, and excludes 'JAR Manifest File', 'ANT buildfile' and all content types defined by PDE and WTP plug-ins.

Get in touch

You can also contact me on Twitter: @j2r2b

License