2013-06-28 72 views
0

我要检查一些java类代码的头部分,我使用的是maven-license-plugin,并且我必须在常见头文件(文本)文件中指定常规表达允许这样的台词:正则表达式来匹配复杂的字符串或行

Portions Copyrighted 2013 andrea

Copyright 2008-2009 Company, Inc. All rights reserved.

你能帮助我吗?

头的模板是​​:

==================== 
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 

Copyright 2008-2009 company, Inc. All rights reserved. 

The contents of this file are subject to the terms of the Common Development 
and Distribution License("CDDL") (the "License"). You may not use this file 
except in compliance with the License. 

You can obtain a copy of the License at https://xxx.yy.com/licenses/CDDL 
See the License for the specific language governing permissions and limitations 
under the License. 

When distributing the Covered Code, include this CDDL Header Notice in each file 
and include the License file at https://xxx.yy.com/licenses/CDDL. 
If applicable, add the following below this CDDL Header, with the fields 
enclosed by brackets [] replaced by your own identifying information: 
"Portions Copyrighted [year] [name of copyright owner]" 
==================== 
+0

你可以说说规则吗?比如哪个字符没有改变,哪些字符会改变? –

+0

,我必须能够识别所发布的模板以及文件末尾的一行,例如部分版权所有2013 andrea以及第一版权之后的附加行:Copyright 2008-2009 Company,Inc.保留所有权利。 – andPat

+0

对这个模板的唯一更改是这两个可能的添加,整个剩余的文本是相同的 – andPat

回答

1

试试这个:

^.*Copyright(ed)?\s+\d+(-\d+)?.+$ 
+0

以及是否需要检查是否存在空白行? – andPat

+0

我认为你的建议非常接近正确的答案,但maven插件仍然无法正常工作,也许在“部分版权保护......”之前无法识别文件末尾可能出现的空行...... – andPat

+0

我用neatbeans做了一些测试,你的表情几乎是完美的,但不符合这种情况:“Copyright(c)2011-2013 ForgeRock AS。All Rights Reserved” – andPat