| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you 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. |
| */ |
| |
| import org.codehaus.plexus.util.FileUtils; |
| |
| import java.io.*; |
| import java.util.*; |
| |
| String[] modules = { "mod-1", "mod-2", "mod-3" }; |
| String[] paths = |
| { |
| "target/site/pmd.html", |
| "target/site/cpd.html", |
| "target/pmd.xml", |
| "target/cpd.xml", |
| }; |
| |
| // files must exist in every module |
| for ( String module : modules ) |
| { |
| // PMD and CPD reports |
| for ( String path : paths ) |
| { |
| File file = new File( basedir, module + '/' + path ); |
| System.out.println( "Checking for existence of " + file ); |
| if ( !file.isFile() ) |
| { |
| throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() ); |
| } |
| } |
| } |
| |
| // files must not exist in parent |
| for ( String path : paths ) |
| { |
| File file = new File( basedir, path ); |
| System.out.println( "Checking for absence of " + file ); |
| if ( file.exists() ) |
| { |
| throw new IOException( "Banned: " + file.getAbsolutePath() ); |
| } |
| } |
| |
| |
| // check PMD rulesets target copy |
| File rule = new File( basedir, "mod-1/target/latin-1.xml" ); |
| String nonascii = "-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF\u00BC\u00BD\u00BE\u00A4"; |
| String content = FileUtils.fileRead( rule, "ISO-8859-1" ); |
| if ( content.indexOf( nonascii ) < 0 ) |
| { |
| throw new IOException( "non-ascii content corrupted in Latin1." ); |
| } |
| rule = new File( basedir, "mod-1/target/utf-8.xml" ); |
| content = FileUtils.fileRead( rule, "UTF-8" ); |
| if ( content.indexOf( nonascii ) < 0 ) |
| { |
| throw new IOException( "non-ascii content corrupted in UTF-8." ); |
| } |
| |
| // check xml files encoding |
| void checkEncoding( String module, String encoding ) |
| { |
| for ( String path : paths ) |
| { |
| if ( !path.endsWith( ".xml" ) ) |
| { |
| continue; |
| } |
| File file = new File( basedir, module + '/' + path ); |
| content = FileUtils.fileRead( file, encoding ); |
| if ( !content.startsWith( "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>" ) ) |
| { |
| throw new IOException( "wrong XML encoding declaration for " + file ); |
| } |
| } |
| } |
| checkEncoding( "mod-1", "ISO-8859-1" ); |
| checkEncoding( "mod-2", "UTF-8" ); |
| checkEncoding( "mod-3", "UTF-8" ); |
| |
| return true; |