import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.batch.protocol.output.issue.ReportIssue;
import org.sonar.core.issue.db.IssueStorage;
-import javax.annotation.Nullable;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
return issue;
}
-
- public void deleteDirectory(@Nullable File directory) {
- if (directory == null) {
- return;
- }
-
- try {
- FileUtils.deleteDirectory(directory);
- } catch (IOException e) {
- LOG.warn(String.format("Failed to delete directory '%s'", directory.getPath()), e);
- }
- }
}
package org.sonar.server.computation;
import com.google.common.collect.Lists;
-import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
sut = new AnalysisReportService(issueStorageFactory);
}
- @Test
- public void clean_null_directory_does_not_throw_any_exception() throws Exception {
- sut.deleteDirectory(null);
- }
-
- @Test
- public void clean_temp_folder() throws Exception {
- File origin = new File(getClass().getResource("/org/sonar/server/computation/AnalysisReportServiceTest/report-folder").getFile());
- File destination = new File("target/tmp/report-folder-to-delete");
- FileUtils.copyDirectory(origin, destination);
- assertThat(destination.exists()).isTrue();
-
- sut.deleteDirectory(destination);
-
- assertThat(destination.exists()).isFalse();
- }
-
@Test
public void load_resources() throws Exception {
File dir = new File(getClass().getResource("/org/sonar/server/computation/AnalysisReportServiceTest/report-folder").getFile());