Skip to content

Commit

Permalink
cxf-tools-common: use Files.copy
Browse files Browse the repository at this point in the history
  • Loading branch information
amarkevich committed Nov 16, 2020
1 parent dcf6d7a commit f5f08c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
Expand Up @@ -21,9 +21,9 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -79,27 +79,25 @@ public void compile(ToolContext context) throws ToolException {
String dirName = fileName.substring(0, fileName.lastIndexOf(File.separator) + 1);

String path = outPutDir + File.separator + dirName;
if (!dirSet.contains(path)) {
if (dirSet.add(path)) {

dirSet.add(path);
File file = new File(path);
if (file.isDirectory() && file.list() != null) {
for (String str : file.list()) {
if (str.endsWith("java")) {
fileList.add(path + str);
} else {
// copy generated xml file or others to class directory
File otherFile = new File(path + File.separator + str);
Path otherFile = Paths.get(path, str);
String suffix = "xml";
if (otherFile.isFile()
if (Files.isReadable(otherFile)
&& str.regionMatches(true, str.length() - suffix.length(), suffix, 0, suffix.length())
&& context.get(ToolConstants.CFG_CLASSDIR) != null) {
String targetDir = (String)context.get(ToolConstants.CFG_CLASSDIR);

File targetFile = new File(targetDir + File.separator + dirName
+ File.separator + str);
try {
copyXmlFile(otherFile, targetFile);
Files.copy(otherFile,
Files.createDirectories(Paths.get(targetDir, dirName)).resolve(str));

} catch (IOException e) {
Message msg = new Message("FAIL_TO_COPY_GENERATED_RESOURCE_FILE", LOG);
Expand All @@ -126,26 +124,4 @@ public void compile(ToolContext context) throws ToolException {
}
}

private void copyXmlFile(File from, File to) throws ToolException, IOException {

String dir = to.getCanonicalPath()
.substring(0, to.getCanonicalPath().lastIndexOf(File.separator));
File dirFile = new File(dir);
dirFile.mkdirs();
try (InputStream input = Files.newInputStream(from.toPath());
OutputStream output = Files.newOutputStream(to.toPath())) {
byte[] b = new byte[1024 * 3];
int len = 0;
while (len != -1) {
len = input.read(b);
if (len != -1) {
output.write(b, 0, len);
}
}
output.flush();
} catch (Exception e) {
Message msg = new Message("FAIL_TO_COPY_GENERATED_RESOURCE_FILE", LOG);
throw new ToolException(msg, e);
}
}
}
Expand Up @@ -58,12 +58,12 @@

public class ProcessorTestBase {

public static final List<String> DEFAULT_IGNORE_ATTR = Arrays.asList(new String[]{"attributeFormDefault",
"elementFormDefault",
"form",
"version",
"part@name"});
public static final List<String> DEFAULT_IGNORE_TAG = Arrays.asList(new String[]{"sequence"});
public static final List<String> DEFAULT_IGNORE_ATTR = Arrays.asList("attributeFormDefault",
"elementFormDefault",
"form",
"version",
"part@name");
public static final List<String> DEFAULT_IGNORE_TAG = Arrays.asList("sequence");

//CHECKSTYLE:OFF
@Rule
Expand Down

0 comments on commit f5f08c8

Please sign in to comment.