Skip to content

Commit

Permalink
Remove .okbuck/gen entirely for okbuck
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautam Korlam committed Apr 14, 2017
1 parent 511292b commit 9bcdad4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class OkBuckGradlePlugin implements Plugin<Project> {
kotlinDeps ? kotlinDeps.right: null)
}

// Cleanup gen folder
FileUtil.deleteQuietly(project.projectDir.toPath().resolve(OKBUCK_GEN))

// Create clean task
Task okBuckClean = project.tasks.create(OKBUCK_CLEAN, OkBuckCleanTask, {
projects = okbuckExt.buckProjects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Sets;
import com.uber.okbuck.OkBuckGradlePlugin;
import com.uber.okbuck.core.model.base.ProjectType;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.ProjectUtil;

import org.gradle.api.DefaultTask;
Expand All @@ -12,11 +13,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -65,13 +63,7 @@ void clean() throws IOException {
difference
.parallelStream()
.map(p -> rootProjectPath.resolve(p).resolve(OkBuckGradlePlugin.BUCK))
.forEach(OkBuckCleanTask::deleteQuietly);

// Delete gen folders
difference
.parallelStream()
.map(p -> rootProjectPath.resolve(OkBuckGradlePlugin.OKBUCK_GEN).resolve(p))
.forEach(OkBuckCleanTask::deleteQuietly);
.forEach(FileUtil::deleteQuietly);

// Save generated project's BUCK file path
Files.write(
Expand All @@ -82,22 +74,4 @@ void clean() throws IOException {
.collect(Collectors.toList())
);
}

private static void deleteQuietly(Path p) {
try {
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException ignored) {}
}
}
22 changes: 22 additions & 0 deletions buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -65,4 +69,22 @@ public static String getIfAvailable(Project project, File file) {
Set<String> available = getIfAvailable(project, Collections.singleton(file));
return available.isEmpty() ? null : available.iterator().next();
}

public static void deleteQuietly(Path p) {
try {
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException ignored) {}
}
}

0 comments on commit 9bcdad4

Please sign in to comment.