import static org.mockito.Mockito.mock;
import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
return (T) proxy;
}
+ /**
+ * removes contents of the directory
+ * @param dir to be cleaned
+ * @throws IOException
+ */
+ protected void cleanDirectory(File dir) throws IOException {
+ if (!dir.isDirectory()) {
+ throw new IllegalStateException("dir must be a directory");
+ }
+
+ final File[] files = dir.listFiles();
+ if (files == null) {
+ throw new IOException("Failed to list contents of " + dir);
+ }
+
+ for (File file : files) {
+ if (file.isDirectory()) {
+ cleanDirectory(dir);
+ }
+ file.delete();
+ }
+ }
+
}
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<Provide-Capability>org.opendaylight.controller.config.persister.storage.adapter</Provide-Capability>
<Import-Package>com.google.common.base,
com.google.common.io,
- org.apache.commons.io,
org.opendaylight.controller.config.persist.api,
org.slf4j,
com.google.common.collect,
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
import javax.management.JMX;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.config.api.ConflictingVersionException;
configurator.setContext(lc);
configurator.doConfigure("src/test/resources/simple_config_logback.xml");
File f = new File("target/it");
- if (f.exists())
- FileUtils.cleanDirectory(f);
+ if (f.exists()) {
+ cleanDirectory(f);
+ }
ch.qos.logback.classic.Logger logger = lc.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
ch.qos.logback.core.rolling.RollingFileAppender<ILoggingEvent> fileAppender = (ch.qos.logback.core.rolling.RollingFileAppender<ILoggingEvent>) logger
.getAppender("VARLOGFILE");
import javax.management.JMX;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.config.api.ConflictingVersionException;
configurator.doConfigure("src/test/resources/simple_config_logback.xml");
File f = new File("target/it");
if (f.exists())
- FileUtils.cleanDirectory(f);
+ cleanDirectory(f);
}
/**
<artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
-
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
serviceLoaderFile.getParentFile().mkdirs();
try {
serviceLoaderFile.createNewFile();
- FileUtils.write(serviceLoaderFile,
- fullyQualifiedNamesOfFactories.toString());
+ Files.write(fullyQualifiedNamesOfFactories.toString(), serviceLoaderFile, StandardCharsets.UTF_8);
} catch (IOException e) {
String message = "Cannot write to " + serviceLoaderFile;
LOG.error(message);
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
+import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Map.Entry;
-import org.apache.commons.io.FileUtils;
import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
public class GeneratedObject {
public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
File dstFile = fqn.toFile(srcDirectory);
- if (overwrite == true || dstFile.exists() == false) {
- FileUtils.write(dstFile, content);
+ if (overwrite || !dstFile.exists()) {
+ Files.createParentDirs(dstFile);
+ Files.touch(dstFile);
+ Files.write(content, dstFile, StandardCharsets.UTF_8);
return Optional.of(Maps.immutableEntry(fqn, dstFile));
} else {
return Optional.absent();
GeneratedObject that = (GeneratedObject) o;
- if (!fqn.equals(that.fqn)) {
- return false;
- }
+ return fqn.equals(that.fqn);
- return true;
}
@Override
package org.opendaylight.controller.config.yangjmxgenerator.plugin;
import java.io.File;
-import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.opendaylight.controller.config.yangjmxgenerator.AbstractYangTest;
@Before
public void cleanUpDirectory() throws Exception {
- FileUtils.deleteDirectory(generatorOutputPath);
+ deleteFolder(generatorOutputPath);
+ }
+
+ public void deleteFolder(File folder) {
+ File[] files = folder.listFiles();
+ if (files != null) {
+ for (File f: files) {
+ if (f.isDirectory()) {
+ deleteFolder(f);
+ } else {
+ f.delete();
+ }
+ }
+ }
+ folder.delete();
}
}
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.IProblem;
generatedResourcesDir, "META-INF", "services",
ModuleFactory.class.getName());
assertThat(moduleFactoryFile.exists(), is(true));
- Set<String> lines = Sets.newHashSet(FileUtils
- .readLines(moduleFactoryFile));
+ Set<String> lines = Sets.newHashSet(Files
+ .readLines(moduleFactoryFile, StandardCharsets.UTF_8));
Set<String> expectedLines = Sets.newHashSet(//
PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX
+ ".threads.java.EventBusModuleFactory",//
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import com.google.common.io.Files;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.Java17Parser;
-import org.apache.commons.io.FileUtils;
import org.opendaylight.controller.config.yangjmxgenerator.plugin.AbstractGeneratorTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
protected Node parse(File dstFile) throws IOException {
assertNotNull(dstFile);
- LOG.debug(FileUtils.readFileToString(dstFile));
+ LOG.debug(Files.toString(dstFile, StandardCharsets.UTF_8));
Parser parser = new Java17Parser(new ParserOptions());
return parser.parse(dstFile.toString(), new FileReader(dstFile));
}
<description>Remove generated source files, after new files generation, implementation is inserted.</description>
<dependencies>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
*/
package org.opendaylight.controller.config.yang.test.plugin;
+import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
-import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
if (sourceFile.getName().endsWith(".java")) {
String sourceContent;
try {
- sourceContent = FileUtils.readFileToString(sourceFile);
+ sourceContent = Files.toString(sourceFile, StandardCharsets.UTF_8);
} catch (IOException e) {
getLog().error(String.format("Cannot read %s", sourceFile.getAbsolutePath()), e);
continue;
if (stubFile.exists()) {
String stubContent = null;
try {
- stubContent = FileUtils.readFileToString(stubFile);
+ stubContent = Files.toString(stubFile, StandardCharsets.UTF_8);
} catch (IOException e) {
getLog().error(String.format("Cannot read %s", stubFile.getAbsolutePath()), e);
}
// replace the file content
try {
- FileUtils.write(sourceFile, sourceContent);
+ Files.write(sourceContent, sourceFile, StandardCharsets.UTF_8);
} catch (IOException e) {
getLog().error(String.format("Cannot write %s", sourceFile.getAbsolutePath()), e);
}
<artifactId>pax-exam-link-mvn</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>