blob: 76eec5120c7ee60f5575010ca1feb758253b8e2e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
/*******************************************************************************
* Copyright (c) 2005, 2007 committers of openArchitectureWare and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* committers of openArchitectureWare - initial API and implementation
*******************************************************************************/
package org.eclipse.m2t.common.recipe.simpleChecks.file;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.eclipse.m2t.common.recipe.core.AtomicCheck;
public class FileContentsHelper {
public static void checkContent( AtomicCheck c, String filename, String substring ) {
StringBuffer b = new StringBuffer();
BufferedReader r;
try {
r = new BufferedReader(new FileReader(filename));
while ( r.ready() ) {
b.append( r.readLine() );
}
if ( b.toString().indexOf(substring) >= 0 ) c.ok();
else c.fail( "file does not contain '"+substring+"'");
} catch (FileNotFoundException e) {
c.fail( "cannot read file: "+filename);
} catch (IOException e) {
c.fail( "cannot read file: "+filename);
}
}
}
|