package de.retest.recheck.ignore;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.retest.recheck.configuration.ProjectConfiguration;
import de.retest.recheck.configuration.ProjectConfigurationUtil;
import de.retest.recheck.review.GlobalIgnoreApplier;
import de.retest.recheck.review.counter.NopCounter;
import de.retest.recheck.review.workers.LoadFilterWorker;

public class RecheckIgnoreUtil {

	private static final Logger logger = LoggerFactory.getLogger( RecheckIgnoreUtil.class );

	private RecheckIgnoreUtil() {}

	public static Optional<Path> getIgnoreFile() {
		return getRetestFile( ProjectConfiguration.RECHECK_IGNORE );
	}

	public static Optional<Path> getIgnoreRuleFile() {
		return getRetestFile( ProjectConfiguration.RECHECK_IGNORE_JSRULES );
	}

	private static Optional<Path> getRetestFile( final String filename ) {
		final Optional<Path> projectConfigurationFolder = ProjectConfigurationUtil.findProjectConfigurationFolder();
		return projectConfigurationFolder.map( p -> p.resolve( filename ) );
	}

	public static GlobalIgnoreApplier loadRecheckIgnore() {
		return loadRecheckSuiteIgnore( new LoadFilterWorker( NopCounter.getInstance() ) );
	}

	public static GlobalIgnoreApplier loadRecheckSuiteIgnore( final File ignoreFilesBasePath ) {
		return loadRecheckSuiteIgnore( new LoadFilterWorker( NopCounter.getInstance(), ignoreFilesBasePath.toPath() ) );
	}

	public static GlobalIgnoreApplier loadRecheckUserIgnore() {
		return loadRecheckSuiteIgnore( new LoadFilterWorker( NopCounter.getInstance(),
				Paths.get( System.getProperty( "user.home" ), ".retest" ) ) );
	}

	private static GlobalIgnoreApplier loadRecheckSuiteIgnore( final LoadFilterWorker loadFilterWorker ) {
		try {
			return loadFilterWorker.load();
		} catch ( final NoSuchFileException | FileNotFoundException e ) {
			logger.debug( "Ignoring missing suite or user ignore file." );
		} catch ( final Exception e ) {
			logger.error( "Exception loading suite or user ignore file.", e );
		}
		return GlobalIgnoreApplier.create( NopCounter.getInstance() );
	}
}

@@ -28,16 +28,80 @@
 gnore;%0A%0A
+import static de.retest.recheck.Properties.RETEST_FOLDER_NAME;%0A%0A
 import j
@@ -143,32 +143,60 @@
 FoundException;%0A
+import java.nio.file.Files;%0A
 import java.nio.
@@ -366,69 +366,8 @@
 y;%0A%0A
-import de.retest.recheck.configuration.ProjectConfiguration;%0A
 impo
@@ -786,667 +786,585 @@
  get
-IgnoreFile() %7B%0A%09%09return getRetestFile( ProjectConfiguration.RECHECK_IGNORE );%0A%09%7D%0A%0A%09public static Optional%3CPath%3E getIgnoreRuleFile() %7B%0A%09%09return getRetestFile( ProjectConfiguration.RECHECK_IGNORE_JSRULES );%0A%09%7D%0A%0A%09private static Optional%3CPath%3E getRetestFile( final String filename ) %7B%0A%09%09final Optional%3CPath%3E projectConfigurationFolder = ProjectConfigurationUtil.findProjectConfigurationFolder();%0A%09%09return projectConfigurationFolder.map( p -%3E p.resolve( filename ) );%0A%09%7D%0A%0A%09public static GlobalIgnoreApplier loadRecheckIgnore() %7B%0A%09%09return loadRecheckSuiteIgnore( new LoadFilterWorker( NopCounter.getInstance() ) );%0A%09%7D%0A%0A%09public static GlobalIgnoreApplier loadRecheck
+ProjectIgnoreFile( final String filename ) %7B%0A%09%09final Optional%3CPath%3E projectConfigurationFolder = ProjectConfigurationUtil.findProjectConfigurationFolder();%0A%09%09return projectConfigurationFolder.map( p -%3E p.resolve( filename ) );%0A%09%7D%0A%0A%09public static Optional%3CPath%3E getUserIgnoreFile( final String filename ) %7B%0A%09%09final Path userIgnoreFile = Paths.get( System.getProperty( %22user.home%22 ), RETEST_FOLDER_NAME, filename );%0A%09%09if ( Files.exists( userIgnoreFile ) ) %7B%0A%09%09%09return Optional.of( userIgnoreFile );%0A%09%09%7D else %7B%0A%09%09%09return Optional.empty();%0A%09%09%7D%0A%09%7D%0A%0A%09public static Optional%3CPath%3E get
 Suit
@@ -1370,24 +1370,28 @@
 teIgnore
+File
 ( final 
 File ign
@@ -1386,151 +1386,268 @@
 nal 
-File ignoreFilesBasePath ) %7B%0A%09%09return loadRecheckSuiteIgnore( new LoadFilterWorker( NopCounter.getInstance(), ignoreFilesBasePath.toPath() ) );
+String filename, final Path basePath ) %7B%0A%09%09final Path suiteIgnoreFile = Paths.get( basePath.toAbsolutePath().toString(), filename );%0A%09%09if ( Files.exists( suiteIgnoreFile ) ) %7B%0A%09%09%09return Optional.of( suiteIgnoreFile );%0A%09%09%7D else %7B%0A%09%09%09return Optional.empty();%0A%09%09%7D
 %0A%09%7D%0A
@@ -1697,19 +1697,47 @@
 heck
-User
 Ignore(
+ final File ignoreFilesBasePath 
 ) %7B%0A
@@ -1820,69 +1820,36 @@
 e(),
-%0A%09%09%09%09Paths.get( System.getProperty( %22user.home%22 ), %22.retest%22 
+ ignoreFilesBasePath.toPath(
 ) ) 

Check if files exist