blob: bd3a59974979582a08da776d0f7dda7588eb25b5 [file] [log] [blame]
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* 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.
*/
package org.jetbrains.jps.model.java.impl.compiler;
import com.intellij.openapi.util.io.FileUtilRt;
import org.jetbrains.jps.util.JpsPathUtil;
import org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
/**
* @author nik
*/
public class JpsCompilerExcludesImpl implements JpsCompilerExcludes {
private final Set<File> myFiles = new HashSet<File>();
private final Set<File> myDirectories = new HashSet<File>();
private final Set<File> myRecursivelyExcludedDirectories = new HashSet<File>();
@Override
public void addExcludedFile(String url) {
addExcludedFile(JpsPathUtil.urlToFile(url));
}
@Override
public void addExcludedDirectory(String url, boolean recursively) {
addExcludedDirectory(JpsPathUtil.urlToFile(url), recursively);
}
protected void addExcludedFile(File file) {
myFiles.add(file);
}
protected void addExcludedDirectory(File dir, boolean recursively) {
(recursively ? myRecursivelyExcludedDirectories : myDirectories).add(dir);
}
@Override
public boolean isExcluded(File file) {
if (myFiles.contains(file)) {
return true;
}
if (!myDirectories.isEmpty() || !myRecursivelyExcludedDirectories.isEmpty()) { // optimization
File parent = FileUtilRt.getParentFile(file);
if (myDirectories.contains(parent)) {
return true;
}
while (parent != null) {
if (myRecursivelyExcludedDirectories.contains(parent)) {
return true;
}
parent = FileUtilRt.getParentFile(parent);
}
}
return false;
}
}