3

IntelliJ adds too many copy right headers

I setup IntelliJ to include a licence into source code as a comment into the header. For some reason IntelliJ repeated the copy right statement for several in all files.

So currently all files have between one and five (or more) repetitions of the licence header, e.g.:

/*
 * Copyright [2014] [John Doe]
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/*
 * Copyright [2014] [John Doe]
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or    implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

How can I remove multiple repetitions of the same header?

I could not find a fuction to remove the headers again. Does IntelliJ provide such a functionality? Should I use Linux board tools and replace tne string? How can I do this safely?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Stefan
  • 679
  • 2
  • 9
  • 21
  • Does it keep adding the copies back under some circumstances after you clean them? A positive answer would greatly expand the problem to be solved. – ivan_pozdeev Feb 24 '15 at 16:11
  • 1
    Yes, IntelliJ adds multiple copy right headers when I activate the setting "Update Copyright" during committing. I would not expect this behaviour. The Help says "To have copyright notices updated correctly, make sure that the keyword specified in the copyright profile is a part of the notice definition. Otherwise, IntelliJ IDEA will not detect copyright notices and, instead of updating existing notices, will insert new ones". I am note sure what keyword I should look for here. – Stefan Feb 25 '15 at 12:19
  • For me I added the same copyright text in the input below that says "Regexp to detect copyright in comments:"... thats what fixed it – Alexandros Kourtis Feb 26 '23 at 10:27

3 Answers3

3

According to Creating Copyright Profiles - IntelliJ IDEA 13.1.0 Web Help (the bold font is mine):

In the Keyword to detect copyright in comments text box, type a character string to distinguish copyright notices from other comments during copyright update.

I.e. it needs to be a single substring unique enough to reliably identify your copyright notice specified in the copyright profile.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
0

You can remove the duplicates by using the same method you used to set them.

Follow the following steps:

  • Open up the custom profile in settings.
  • Set the regexp to use to detect the copyright as Copyright
  • Set the 'allow replacing copyright...' field to something that is in your current copyright that is duplicate, e.g. John Doe in your example.

This will replace all duplicates with a single copyright. Tweak it until it matches.

Alwyn Schoeman
  • 467
  • 7
  • 13
-3

It is extremely rare that copyright notices and licenses need to be removed from a source file, so it is unlikely that an editor/IDE would provide a function to do it with one keystroke.

If the copyright notices/licenses are identical, then you can safely remove all but one of them.
If you are the copyright holder, then you can remove all those notices.

To remove them, just select the text and delete it.

Bart van Ingen Schenau
  • 15,488
  • 4
  • 32
  • 41