Use the new File API.
diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/WebContainerUtils.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/WebContainerUtils.java
index 15058f2..2e1cbad 100644
--- a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/WebContainerUtils.java
+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/WebContainerUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,10 +16,12 @@
package org.eclipse.gemini.web.internal;
-import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Dictionary;
import java.util.Locale;
@@ -218,7 +220,7 @@
public static boolean isDirectory(URL source) {
if (FILE_SCHEME.equals(source.getProtocol())) {
try {
- return sourceAsFile(source).isDirectory();
+ return Files.isDirectory(sourceAsPath(source));
} catch (URISyntaxException e) {
LOGGER.warn("Unable to determine if bundle '" + source + "'is a directory.", e);
}
@@ -226,11 +228,11 @@
return false;
}
- public static File sourceAsFile(URL source) throws URISyntaxException {
+ public static Path sourceAsPath(URL source) throws URISyntaxException {
URI uri = source.toURI();
if (uri.isOpaque()) {
- return new File(uri.getSchemeSpecificPart());
+ return Paths.get(uri.getSchemeSpecificPart());
}
- return new File(uri);
+ return Paths.get(uri);
}
}
diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformer.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformer.java
index e5bd89f..ac31fa7 100644
--- a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformer.java
+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 SAP AG
+ * Copyright (c) 2010, 2015 SAP AG
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -19,15 +19,18 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
+import java.nio.file.CopyOption;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.jar.JarFile;
-import org.eclipse.virgo.util.io.PathReference;
-
/**
* Utility class for transforming the files in a directory.
* <p/>
@@ -61,7 +64,7 @@
* @return <code>true</code> if the file was transformed, otherwise <code>false</code>
* @throws IOException if transformation fails
*/
- boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException;
+ boolean transformFile(InputStream inputStream, Path toFile) throws IOException;
}
private static final String MANIFEST_VERSION_HEADER = "Manifest-Version: 1.0";
@@ -101,42 +104,41 @@
* @throws IOException if the directory cannot be transformed.
*/
void transform(URL url, URL transformedUrl, boolean ensureManifestIsPresent) throws IOException {
- PathReference fromDirectory = new PathReference(url.getPath());
- PathReference toDirectory = new PathReference(transformedUrl.getPath());
+ Path fromDirectory = Paths.get(url.getPath());
+ Path toDirectory = Paths.get(transformedUrl.getPath());
transformDir(fromDirectory, toDirectory);
- PathReference manifest = fromDirectory.newChild(JarFile.MANIFEST_NAME);
- if (ensureManifestIsPresent && !manifest.exists()) {
- PathReference toFile = toDirectory.newChild(JarFile.MANIFEST_NAME);
- toFile.getParent().createDirectory();
+ Path manifest = fromDirectory.resolve(JarFile.MANIFEST_NAME);
+ if (ensureManifestIsPresent && Files.notExists(manifest)) {
+ Path toFile = toDirectory.resolve(JarFile.MANIFEST_NAME);
+ Files.createDirectories(toFile.getParent());
try (InputStream defaultManifestStream = getDefaultManifestStream();) {
this.callback.transformFile(defaultManifestStream, toFile);
}
}
}
- private void transformDir(PathReference fromDirectory, PathReference toDirectory) throws IOException {
- File[] fileList = fromDirectory.toFile().listFiles();
- PathReference fromFile = null;
- for (int i = 0; fileList != null && i < fileList.length; i++) {
- fromFile = new PathReference(fileList[i]);
- PathReference toFile = toDirectory.newChild(fromFile.getName());
- if (!fromFile.isDirectory()) {
- transformFile(fromFile, toFile);
- } else {
- transformDir(fromFile, toFile);
+ private void transformDir(Path fromDirectory, final Path toDirectory) throws IOException {
+ try (DirectoryStream<Path> fileList = Files.newDirectoryStream(fromDirectory);) {
+ for (Path fromFile : fileList) {
+ Path toFile = toDirectory.resolve(fromFile.getFileName());
+ if (!Files.isDirectory(fromFile)) {
+ transformFile(fromFile, toFile);
+ } else {
+ transformDir(fromFile, toFile);
+ }
}
}
}
- private void transformFile(PathReference fromFile, PathReference toFile) throws IOException {
+ private void transformFile(Path fromFile, Path toFile) throws IOException {
boolean transformed = false;
- try (FileInputStream fis = new FileInputStream(fromFile.toFile());) {
+ try (InputStream fis = Files.newInputStream(fromFile);) {
transformed = this.callback.transformFile(fis, toFile);
}
if (!transformed) {
- toFile.getParent().createDirectory();
- fromFile.copy(toFile);
+ Files.createDirectories(toFile.getParent());
+ Files.copy(fromFile, toFile, new CopyOption[] { StandardCopyOption.REPLACE_EXISTING });
}
}
diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnection.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnection.java
index 2104f76..69e4c6b 100644
--- a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnection.java
+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG
+ * Copyright (c) 2010, 2015 SAP AG
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -19,11 +19,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
-
-import org.eclipse.virgo.util.io.PathReference;
+import java.nio.file.Paths;
/**
* Implementation of {@link URLConnection} that transforms directory files as they are read.
@@ -53,7 +51,6 @@
* @param transformer the <code>DirTransformer</code> to apply as content is being read.
* @throws MalformedURLException the exception is thrown in case the new URL, where is the transformed data, cannot
* be created.
- * @throws URISyntaxException
*/
DirTransformingURLConnection(URL url, DirTransformer transformer) throws MalformedURLException {
this(url, transformer, false);
@@ -69,7 +66,6 @@
* @param ensureManifestIsPresent <code>true</code> if the presence of a MANIFEST.MF should be ensured.
* @throws MalformedURLException the exception is thrown in case the new URL, where is the transformed data, cannot
* be created.
- * @throws URISyntaxException
*/
DirTransformingURLConnection(URL url, DirTransformer transformer, boolean ensureManifestIsPresent) throws MalformedURLException {
super(url);
@@ -77,8 +73,7 @@
this.ensureManifestIsPresent = ensureManifestIsPresent;
this.transformedURL = new URL(TEMP_DIR + getPath());
- PathReference transformedDir = new PathReference(this.transformedURL.getPath());
- transformedDir.delete(true);
+ FileUtils.deleteDirectory(Paths.get(this.transformedURL.getPath()));
}
@Override
diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/FileUtils.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/FileUtils.java
new file mode 100644
index 0000000..0e0d20a
--- /dev/null
+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/FileUtils.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2015 SAP AG
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * Violeta Georgieva - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.gemini.web.internal.url;
+
+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;
+
+final class FileUtils {
+
+ private FileUtils() {
+ }
+
+ static boolean deleteDirectory(Path path) {
+ try {
+ Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ });
+ } catch (IOException e) {
+ return false;
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java
index 86df315..71ccaca 100644
--- a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java
+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,14 +16,15 @@
package org.eclipse.gemini.web.internal.url;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
@@ -41,10 +42,6 @@
final class WebBundleScanner {
- private static final String LIB_DIR_SUFFIX = File.separator + "WEB-INF" + File.separator + "lib";
-
- private static final String CLASSES_DIR_SUFFIX = File.separator + "WEB-INF" + File.separator + "classes";
-
private static final String FILE_SCHEME = "file";
private static final String JAR_SUFFIX = ".jar";
@@ -113,13 +110,13 @@
private void scanWarDirectory() throws IOException {
try {
- File bundleDir = WebContainerUtils.sourceAsFile(this.source);
- File libDir = new File(bundleDir, LIB_DIR_SUFFIX);
- if (libDir.isDirectory()) {
+ java.nio.file.Path bundleDir = WebContainerUtils.sourceAsPath(this.source);
+ java.nio.file.Path libDir = bundleDir.resolve("WEB-INF").resolve("lib");
+ if (Files.isDirectory(libDir)) {
doScanLibDirectory(libDir);
}
- File classesDir = new File(bundleDir, CLASSES_DIR_SUFFIX);
- if (classesDir.isDirectory()) {
+ java.nio.file.Path classesDir = bundleDir.resolve("WEB-INF").resolve("classes");
+ if (Files.isDirectory(classesDir)) {
doScanClassesDirectory(classesDir);
}
} catch (URISyntaxException e) {
@@ -127,12 +124,11 @@
}
}
- private void doScanLibDirectory(File libDir) throws IOException {
- File[] files = libDir.listFiles();
- if (files != null) {
- for (File file : files) {
- if (file.isFile() && file.getName().endsWith(JAR_SUFFIX)) {
- String pathToJar = LIB_ENTRY_PREFIX + file.getName();
+ private void doScanLibDirectory(java.nio.file.Path libDir) throws IOException {
+ try (DirectoryStream<java.nio.file.Path> files = Files.newDirectoryStream(libDir)) {
+ for (java.nio.file.Path file : files) {
+ if (!Files.isDirectory(file) && file.getFileName().toString().endsWith(JAR_SUFFIX)) {
+ String pathToJar = LIB_ENTRY_PREFIX + file.getFileName().toString();
if (driveCallBackIfNewJarFound(pathToJar)) {
doScanNestedJar(file);
}
@@ -151,22 +147,21 @@
return true;
}
- private void doScanNestedJar(File file) throws IOException {
- try (JarInputStream jis = new JarInputStream(new FileInputStream(file));) {
- doScanNestedJar(file.getAbsolutePath(), jis);
+ private void doScanNestedJar(java.nio.file.Path file) throws IOException {
+ try (JarInputStream jis = new JarInputStream(Files.newInputStream(file));) {
+ doScanNestedJar(file.toAbsolutePath().toString(), jis);
} catch (IOException e) {
- throw new IOException("Cannot scan " + file.getAbsolutePath(), e);
+ throw new IOException("Cannot scan " + file.toAbsolutePath().toString(), e);
}
}
- private void doScanClassesDirectory(File classesDir) {
- File[] files = classesDir.listFiles();
- if (files != null) {
- for (File file : files) {
- if (file.isDirectory()) {
+ private void doScanClassesDirectory(java.nio.file.Path classesDir) throws IOException {
+ try (DirectoryStream<java.nio.file.Path> files = Files.newDirectoryStream(classesDir)) {
+ for (java.nio.file.Path file : files) {
+ if (Files.isDirectory(file)) {
doScanClassesDirectory(file);
- } else if (file.isFile() && file.getName().endsWith(CLASS_SUFFIX)) {
- String path = normalizePath(file.getPath());
+ } else if (file.getFileName().toString().endsWith(CLASS_SUFFIX)) {
+ String path = normalizePath(file.toString());
this.callBack.classFound(path.substring(path.lastIndexOf(CLASSES_ENTRY_PREFIX) + CLASSES_ENTRY_PREFIX.length()));
}
}
@@ -242,14 +237,14 @@
private void scanNestedJarInWarDirectory(Path directoryPath, String jarPath) throws IOException {
Path entryPath = directoryPath.applyRelativePath(new Path(jarPath));
try {
- File bundleDir = WebContainerUtils.sourceAsFile(this.source);
- File nestedJar = new File(entryPath.toString());
+ java.nio.file.Path bundleDir = WebContainerUtils.sourceAsPath(this.source);
+ java.nio.file.Path nestedJar = Paths.get(entryPath.toString());
if (!nestedJar.isAbsolute()) {
- nestedJar = new File(bundleDir, entryPath.toString());
+ nestedJar = bundleDir.resolve(entryPath.toString());
}
- if (nestedJar.isFile()) {
- URI pathToJar = bundleDir.toURI().relativize(nestedJar.toURI());
- if (pathToJar.equals(nestedJar.toURI())) {
+ if (!Files.isDirectory(nestedJar)) {
+ URI pathToJar = bundleDir.toUri().relativize(nestedJar.toUri());
+ if (pathToJar.equals(nestedJar.toUri())) {
// Do nothing - cannot obtain relative path
return;
}
diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerService.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerService.java
index bd0dcaf..91f2cbb 100644
--- a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerService.java
+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -17,13 +17,15 @@
package org.eclipse.gemini.web.internal.url;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.jar.Attributes;
@@ -39,7 +41,6 @@
import org.eclipse.virgo.util.io.JarTransformer;
import org.eclipse.virgo.util.io.JarTransformer.JarTransformerCallback;
import org.eclipse.virgo.util.io.JarTransformingURLConnection;
-import org.eclipse.virgo.util.io.PathReference;
import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
import org.osgi.service.url.AbstractURLStreamHandlerService;
@@ -77,9 +78,9 @@
private static final class Callback implements JarTransformerCallback, DirTransformerCallback {
- private static final String META_INF = "META-INF";
+ private static final Path META_INF = Paths.get("META-INF");
- private static final String MANIFEST_MF = "MANIFEST.MF";
+ private static final Path MANIFEST_MF = Paths.get("MANIFEST.MF");
private final WebBundleManifestTransformer transformer;
@@ -123,7 +124,7 @@
private boolean isSignatureFile(String entryName) {
String[] entryNameComponents = entryName.split("/");
if (entryNameComponents.length == 2) {
- if (META_INF.equals(entryNameComponents[0])) {
+ if ("META-INF".equals(entryNameComponents[0])) {
String entryFileName = entryNameComponents[1];
if (entryFileName.endsWith(".SF") || entryFileName.endsWith(".DSA") || entryFileName.endsWith(".RSA")) {
return true;
@@ -148,10 +149,10 @@
}
@Override
- public boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException {
- if (MANIFEST_MF.equals(toFile.getName()) && META_INF.equals(toFile.getParent().getName())) {
- toFile.getParent().createDirectory();
- try (OutputStream outputStream = new FileOutputStream(toFile.toFile());) {
+ public boolean transformFile(InputStream inputStream, Path toFile) throws IOException {
+ if (MANIFEST_MF.equals(toFile.getFileName()) && META_INF.equals(toFile.getParent().getFileName())) {
+ Files.createDirectories(toFile.getParent());
+ try (OutputStream outputStream = Files.newOutputStream(toFile);) {
transformManifest(inputStream, outputStream);
}
return true;
@@ -162,9 +163,9 @@
return isSignatureFile(toFile);
}
- private boolean isSignatureFile(PathReference file) {
- if (META_INF.equals(file.getParent().getName())) {
- String fileName = file.getName();
+ private boolean isSignatureFile(Path file) {
+ if (META_INF.equals(file.getParent().getFileName())) {
+ String fileName = file.getFileName().toString();
if (fileName.endsWith(".SF") || fileName.endsWith(".DSA") || fileName.endsWith(".RSA")) {
return true;
}
diff --git a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformerTests.java b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformerTests.java
index e770d95..555f89e 100644
--- a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformerTests.java
+++ b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 SAP AG
+ * Copyright (c) 2010, 2015 SAP AG
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -20,13 +20,13 @@
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
@@ -34,18 +34,17 @@
import java.util.jar.Manifest;
import org.eclipse.gemini.web.internal.url.DirTransformer.DirTransformerCallback;
-import org.eclipse.virgo.util.io.PathReference;
import org.junit.Test;
public class DirTransformerTests {
private static final String WEB_INF = "WEB-INF";
- private static final String META_INF = "META-INF";
+ private static final Path META_INF = Paths.get("META-INF");
private static final String WEB_XML = "web.xml";
- private static final String MANIFEST_MF = "MANIFEST.MF";
+ private static final Path MANIFEST_MF = Paths.get("MANIFEST.MF");
private static final String HEADER_1 = "Manifest-Version: 1.0";
@@ -63,36 +62,37 @@
URL tempDirectory = new URL(TARGET_URL);
// Create content
- PathReference webAppDir = new PathReference(directory.getPath());
- PathReference webXml = webAppDir.newChild(WEB_INF + File.separator + WEB_XML);
- webXml.createFile();
- PathReference manifest = webAppDir.newChild(JarFile.MANIFEST_NAME);
+ Path webAppDir = Paths.get(directory.getPath());
+ Path webXml = webAppDir.resolve(WEB_INF).resolve(WEB_XML);
+ Files.createDirectories(webXml.getParent());
+ Files.createFile(webXml);
+ Path manifest = webAppDir.resolve(JarFile.MANIFEST_NAME);
- final List<PathReference> transformedFiles = new ArrayList<>();
+ final List<Path> transformedFiles = new ArrayList<>();
DirTransformer transformer = new DirTransformer(new DirTransformerCallback() {
@Override
- public boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException {
+ public boolean transformFile(InputStream inputStream, Path toFile) throws IOException {
transformedFiles.add(toFile);
return false;
}
});
- PathReference tempWebAppDir = new PathReference(tempDirectory.getPath());
+ Path tempWebAppDir = Paths.get(tempDirectory.getPath());
transformer.transform(directory, tempDirectory, false);
assertEquals(1, transformedFiles.size());
- assertTrue(!manifest.exists());
+ assertTrue(Files.notExists(manifest));
assertTrue(!transformedFiles.contains(manifest));
- assertTrue(tempWebAppDir.delete(true));
+ assertTrue(FileUtils.deleteDirectory(tempWebAppDir));
transformedFiles.clear();
transformer.transform(directory, tempDirectory, true);
assertEquals(2, transformedFiles.size());
- assertTrue(!manifest.exists());
- assertTrue(transformedFiles.contains(tempWebAppDir.newChild(JarFile.MANIFEST_NAME)));
+ assertTrue(Files.notExists(manifest));
+ assertTrue(transformedFiles.contains(tempWebAppDir.resolve(JarFile.MANIFEST_NAME)));
- assertTrue(tempWebAppDir.delete(true));
- assertTrue(webAppDir.delete(true));
+ assertTrue(FileUtils.deleteDirectory(tempWebAppDir));
+ assertTrue(FileUtils.deleteDirectory(webAppDir));
}
@Test
@@ -101,18 +101,18 @@
URL tempDirectory = new URL(TARGET_URL);
// Create content
- PathReference webAppDir = new PathReference(directory.getPath());
- PathReference manifest = webAppDir.newChild(JarFile.MANIFEST_NAME);
- manifest.getParent().createDirectory();
- createManifest(manifest.toFile(), HEADER_1, HEADER_2);
+ Path webAppDir = Paths.get(directory.getPath());
+ Path manifest = webAppDir.resolve(JarFile.MANIFEST_NAME);
+ Files.createDirectories(manifest.getParent());
+ createManifest(manifest, HEADER_1, HEADER_2);
DirTransformer transformer = new DirTransformer(new DirTransformerCallback() {
@Override
- public boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException {
- if (MANIFEST_MF.equals(toFile.getName()) && META_INF.equals(toFile.getParent().getName())) {
- toFile.getParent().createDirectory();
- createManifest(toFile.toFile(), HEADER_3);
+ public boolean transformFile(InputStream inputStream, Path toFile) throws IOException {
+ if (MANIFEST_MF.equals(toFile.getFileName()) && META_INF.equals(toFile.getParent().getFileName())) {
+ Files.createDirectories(toFile.getParent());
+ createManifest(toFile, HEADER_3);
return true;
}
return false;
@@ -120,11 +120,11 @@
});
transformer.transform(directory, tempDirectory);
- PathReference tempWebAppDir = new PathReference(tempDirectory.getPath());
- checkManifest(tempWebAppDir.newChild(JarFile.MANIFEST_NAME).toFile());
+ Path tempWebAppDir = Paths.get(tempDirectory.getPath());
+ checkManifest(tempWebAppDir.resolve(JarFile.MANIFEST_NAME));
- assertTrue(tempWebAppDir.delete(true));
- assertTrue(webAppDir.delete(true));
+ assertTrue(FileUtils.deleteDirectory(tempWebAppDir));
+ assertTrue(FileUtils.deleteDirectory(webAppDir));
}
@Test
@@ -133,9 +133,10 @@
URL tempDirectory = new URL(TARGET_URL);
// Create content
- PathReference webAppDir = new PathReference(directory.getPath());
- PathReference webXml = webAppDir.newChild(WEB_INF + File.separator + WEB_XML);
- webXml.createFile();
+ Path webAppDir = Paths.get(directory.getPath());
+ Path webXml = webAppDir.resolve(WEB_INF).resolve(WEB_XML);
+ Files.createDirectories(webXml.getParent());
+ Files.createFile(webXml);
try {
new DirTransformer(null);
@@ -146,25 +147,25 @@
DirTransformer transformer = new DirTransformer(new DirTransformerCallback() {
@Override
- public boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException {
+ public boolean transformFile(InputStream inputStream, Path toFile) throws IOException {
return false;
}
});
transformer.transform(directory, tempDirectory);
- PathReference tempWebAppDir = new PathReference(tempDirectory.getPath());
- assertDirsSame(webAppDir.toFile(), tempWebAppDir.toFile());
+ Path tempWebAppDir = Paths.get(tempDirectory.getPath());
+ assertDirsSame(webAppDir, tempWebAppDir);
- assertTrue(tempWebAppDir.delete(true));
- assertTrue(webAppDir.delete(true));
+ assertTrue(FileUtils.deleteDirectory(tempWebAppDir));
+ assertTrue(FileUtils.deleteDirectory(webAppDir));
}
- private void assertDirsSame(File source, File destination) throws IOException {
- assertEquals(source.getName(), destination.getName());
- assertEquals(source.length(), destination.length());
+ private void assertDirsSame(Path webAppDir, Path tempWebAppDir) throws IOException {
+ assertEquals(webAppDir.getFileName(), tempWebAppDir.getFileName());
+ assertEquals(webAppDir.toFile().length(), tempWebAppDir.toFile().length());
- File[] sourceFiles = source.listFiles();
- File[] destinationFiles = destination.listFiles();
+ File[] sourceFiles = webAppDir.toFile().listFiles();
+ File[] destinationFiles = tempWebAppDir.toFile().listFiles();
if (sourceFiles != null && destinationFiles != null) {
assertEquals(sourceFiles.length, destinationFiles.length);
@@ -177,8 +178,8 @@
}
}
- private void checkManifest(File manifestFile) throws IOException {
- try (InputStream is = new FileInputStream(manifestFile);) {
+ private void checkManifest(Path manifestFile) throws IOException {
+ try (InputStream is = Files.newInputStream(manifestFile);) {
Manifest manifest = new Manifest(is);
Attributes attr = manifest.getMainAttributes();
String value = attr.getValue("Custom-Header");
@@ -187,8 +188,8 @@
}
}
- private void createManifest(File manifest, String... headers) throws IOException {
- try (OutputStream outputStream = new FileOutputStream(manifest); PrintWriter writer = new PrintWriter(manifest);) {
+ private void createManifest(Path toFile, String... headers) throws IOException {
+ try (PrintWriter writer = new PrintWriter(Files.newOutputStream(toFile))) {
for (String header : headers) {
writer.println(header);
}
diff --git a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnectionTests.java b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnectionTests.java
index fc64b0e..97b7dad 100644
--- a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnectionTests.java
+++ b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/DirTransformingURLConnectionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 SAP AG
+ * Copyright (c) 2010, 2015 SAP AG
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -19,15 +19,16 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.gemini.web.internal.url.DirTransformer.DirTransformerCallback;
-import org.eclipse.virgo.util.io.PathReference;
import org.junit.Test;
public class DirTransformingURLConnectionTests {
@@ -46,15 +47,16 @@
URL tempDirectory = new URL(TARGET_URL);
// Create content
- PathReference webAppDir = new PathReference(directory.getPath());
- PathReference webXml = webAppDir.newChild(WEB_INF + File.separator + WEB_XML);
- webXml.createFile();
+ Path webAppDir = Paths.get(directory.getPath());
+ Path webXml = webAppDir.resolve(WEB_INF).resolve(WEB_XML);
+ Files.createDirectories(webXml.getParent());
+ Files.createFile(webXml);
- final List<PathReference> files = new ArrayList<>();
+ final List<Path> files = new ArrayList<>();
DirTransformer transformer = new DirTransformer(new DirTransformerCallback() {
@Override
- public boolean transformFile(InputStream inputStream, PathReference toFile) throws IOException {
+ public boolean transformFile(InputStream inputStream, Path toFile) throws IOException {
files.add(toFile);
return false;
}
@@ -68,11 +70,11 @@
URL url = connection.getURL();
assertTrue(tempDirectory.equals(url));
- PathReference tempWebAppDir = new PathReference(tempDirectory.getPath());
- assertTrue(tempWebAppDir.newChild(WEB_INF + File.separator + WEB_XML).exists());
+ Path tempWebAppDir = Paths.get(tempDirectory.getPath());
+ assertTrue(Files.exists(tempWebAppDir.resolve(WEB_INF).resolve(WEB_XML)));
assertTrue(files.size() == 1);
- assertTrue(tempWebAppDir.delete(true));
- assertTrue(webAppDir.delete(true));
+ assertTrue(FileUtils.deleteDirectory(tempWebAppDir));
+ assertTrue(FileUtils.deleteDirectory(webAppDir));
}
}
diff --git a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java
index 86d480c..b7c6f6a 100644
--- a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java
+++ b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -19,22 +19,25 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
-import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import org.easymock.EasyMock;
-import org.eclipse.virgo.util.io.JarUtils;
-import org.eclipse.virgo.util.io.PathReference;
import org.junit.Test;
public class WebBundleScannerTests {
- private static final File WAR_FILE = new File("target/resources/simple-war.war");
+ private static final Path WAR_FILE = Paths.get("target/resources/simple-war.war");
- private static final File WAR_CLASSPATHDEPS = new File("../org.eclipse.gemini.web.test/src/test/resources/classpathdeps.war");
+ private static final Path WAR_CLASSPATHDEPS = Paths.get("../org.eclipse.gemini.web.test/src/test/resources/classpathdeps.war");
- private static final File WAR_WITH_CORRUPTED_JAR = new File("src/test/resources/contains-jar-with-bad-formated-manifest");
+ private static final Path WAR_WITH_CORRUPTED_JAR = Paths.get("src/test/resources/contains-jar-with-bad-formated-manifest");
@Test
public void testScanClasspathDeps() throws IOException {
@@ -42,7 +45,7 @@
setExpectationsClasspathDeps(callback);
- scan(WAR_CLASSPATHDEPS.toURI().toURL(), callback);
+ scan(WAR_CLASSPATHDEPS.toUri().toURL(), callback);
}
@Test
@@ -51,7 +54,7 @@
setExpectations(callback);
- scan(WAR_FILE.toURI().toURL(), callback);
+ scan(WAR_FILE.toUri().toURL(), callback);
}
private void setExpectationsClasspathDeps(WebBundleScannerCallback callback) {
@@ -101,57 +104,56 @@
setExpectationsIncludingNestedJars(callback);
- scan(WAR_FILE.toURI().toURL(), callback, true);
+ scan(WAR_FILE.toUri().toURL(), callback, true);
}
@Test
public void testScanDir() throws Exception {
- PathReference pr = unpackToDir(WAR_FILE);
+ Path pr = unpackToDir(WAR_FILE);
try {
WebBundleScannerCallback callback = EasyMock.createMock(WebBundleScannerCallback.class);
setExpectations(callback);
- scan(pr.toURI().toURL(), callback);
+ scan(pr.toUri().toURL(), callback);
} finally {
- pr.delete(true);
+ FileUtils.deleteDirectory(pr);
}
}
@Test
public void testScanDirIncludingNestedJars() throws Exception {
- PathReference pr = unpackToDir(WAR_FILE);
+ Path pr = unpackToDir(WAR_FILE);
try {
WebBundleScannerCallback callback = EasyMock.createMock(WebBundleScannerCallback.class);
setExpectationsIncludingNestedJars(callback);
- scan(pr.toURI().toURL(), callback, true);
+ scan(pr.toUri().toURL(), callback, true);
} finally {
- pr.delete(true);
+ FileUtils.deleteDirectory(pr);
}
}
@Test
public void testScanDirIncludingClasspathDeps() throws Exception {
- PathReference pr = unpackToDir(WAR_CLASSPATHDEPS);
+ Path pr = unpackToDir(WAR_CLASSPATHDEPS);
try {
WebBundleScannerCallback callback = EasyMock.createMock(WebBundleScannerCallback.class);
setExpectationsClasspathDeps(callback);
- scan(pr.toURI().toURL(), callback, true);
+ scan(pr.toUri().toURL(), callback, true);
} finally {
- pr.delete(true);
+ FileUtils.deleteDirectory(pr);
}
}
@Test(expected = IOException.class)
public void testScanDirWithCorruptedNestedJars() throws Exception {
- PathReference pr = new PathReference(WAR_WITH_CORRUPTED_JAR);
WebBundleScannerCallback callback = EasyMock.createMock(WebBundleScannerCallback.class);
callback.jarFound("WEB-INF/lib/jarfile.jar");
- scan(pr.toURI().toURL(), callback, true);
+ scan(WAR_WITH_CORRUPTED_JAR.toUri().toURL(), callback, true);
}
private void scan(final URL url, final WebBundleScannerCallback callback) throws IOException {
@@ -167,11 +169,21 @@
verify(callback);
}
- private PathReference unpackToDir(File warFile) throws IOException {
- String tmpDir = System.getProperty("java.io.tmpdir");
- PathReference dest = new PathReference(new File(tmpDir, "unpack-" + System.currentTimeMillis()));
- PathReference src = new PathReference(warFile);
- JarUtils.unpackTo(src, dest);
- return dest;
+ private Path unpackToDir(Path warFile) throws IOException {
+ Path destination = Paths.get(System.getProperty("java.io.tmpdir"), "unpack-" + System.currentTimeMillis());
+ Files.createDirectories(destination);
+ try (ZipFile zip = new ZipFile(warFile.toFile());) {
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ Path entryPath = destination.resolve(entry.getName());
+ if (entry.isDirectory()) {
+ Files.createDirectories(entryPath);
+ } else {
+ Files.copy(zip.getInputStream(entry), entryPath);
+ }
+ }
+ }
+ return destination;
}
}
diff --git a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerServiceTests.java b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerServiceTests.java
index 60c3753..b61050c 100644
--- a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerServiceTests.java
+++ b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleUrlStreamHandlerServiceTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -20,16 +20,15 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -38,8 +37,6 @@
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
-import org.eclipse.virgo.util.io.FileSystemUtils;
-import org.eclipse.virgo.util.io.PathReference;
import org.junit.Test;
public class WebBundleUrlStreamHandlerServiceTests {
@@ -69,12 +66,14 @@
URL tempDirectory = new URL("file:target/test-classes/temp/web-app-dir");
// Create content
- PathReference webAppDir = new PathReference(directory.getPath());
- PathReference webXml = webAppDir.newChild("WEB-INF" + File.separator + "web.xml");
- webXml.createFile();
+ Path webAppDir = Paths.get(directory.getPath());
+ Path webXml = webAppDir.resolve("WEB-INF").resolve("web.xml");
+ Files.createDirectories(webXml.getParent());
+ Files.createFile(webXml);
- PathReference signatureFile = webAppDir.newChild("META-INF" + File.separator + "signature.SF");
- signatureFile.createFile();
+ Path signatureFile = webAppDir.resolve("META-INF").resolve("signature.SF");
+ Files.createDirectories(signatureFile.getParent());
+ Files.createFile(signatureFile);
// There is no Manifest in the directory
// Expectation: Manifest will have Web-ContextPath header
@@ -82,13 +81,13 @@
DirTransformingURLConnection connection = (DirTransformingURLConnection) url.toURL().openConnection();
assertNotNull(connection);
connection.setTransformedURL(tempDirectory);
- checkContent(connection, "/test", webXml.toFile());
- assertTrue(FileSystemUtils.deleteRecursively(tempDirectory.getPath()));
+ checkContent(connection, "/test", webXml);
+ assertTrue(FileUtils.deleteDirectory(Paths.get(tempDirectory.getPath())));
// Create content
- PathReference manifest = webAppDir.newChild(JarFile.MANIFEST_NAME);
- manifest.createFile();
- createManifest(manifest.toFile(), "Manifest-Version: 1.0", "Class-Path: ");
+ Path manifest = webAppDir.resolve(JarFile.MANIFEST_NAME);
+ Files.createDirectories(manifest.getParent());
+ createManifest(manifest, "Manifest-Version: 1.0", "Class-Path: ");
// There is Manifest in the directory with basic headers
// Expectation: Manifest will have Web-ContextPath header
@@ -96,11 +95,11 @@
connection = (DirTransformingURLConnection) url.toURL().openConnection();
assertNotNull(connection);
connection.setTransformedURL(tempDirectory);
- checkContent(connection, "/test1", webXml.toFile());
- assertTrue(FileSystemUtils.deleteRecursively(tempDirectory.getPath()));
+ checkContent(connection, "/test1", webXml);
+ assertTrue(FileUtils.deleteDirectory(Paths.get(tempDirectory.getPath())));
// Create content
- createManifest(manifest.toFile(), "Manifest-Version: 1.0", "Class-Path: ", "Web-ContextPath: /test2");
+ createManifest(manifest, "Manifest-Version: 1.0", "Class-Path: ", "Web-ContextPath: /test2");
// There is Manifest in the directory with basic headers +
// Web-ContextPath header
@@ -109,20 +108,20 @@
connection = (DirTransformingURLConnection) url.toURL().openConnection();
assertNotNull(connection);
connection.setTransformedURL(tempDirectory);
- checkContent(connection, "/test2", webXml.toFile());
- assertTrue(FileSystemUtils.deleteRecursively(tempDirectory.getPath()));
+ checkContent(connection, "/test2", webXml);
+ assertTrue(FileUtils.deleteDirectory(Paths.get(tempDirectory.getPath())));
- assertTrue(FileSystemUtils.deleteRecursively(directory.getPath()));
+ assertTrue(FileUtils.deleteDirectory(Paths.get(directory.getPath())));
}
- private void checkContent(URLConnection connection, String contextPath, File webXml) throws Exception {
+ private void checkContent(URLConnection connection, String contextPath, Path webXml) throws Exception {
try (InputStream inputStream = connection.getInputStream();) {
assertNotNull(inputStream);
}
- File webAppDir = new File(connection.getURL().getPath());
+ Path webAppDir = Paths.get(connection.getURL().getPath());
// Check Manifest
- try (InputStream is = new FileInputStream(new File(webAppDir, JarFile.MANIFEST_NAME));) {
+ try (InputStream is = Files.newInputStream(webAppDir.resolve(JarFile.MANIFEST_NAME));) {
Manifest manifest = new Manifest(is);
Attributes mainAttributes = manifest.getMainAttributes();
Set<Entry<Object, Object>> entrySet = mainAttributes.entrySet();
@@ -135,15 +134,15 @@
}
// Check web.xml
- assertEquals(webXml.length(), new File(webAppDir, "WEB-INF" + File.separator + "web.xml").length());
+ assertEquals(webXml.toFile().length(), webAppDir.resolve("WEB-INF").resolve("web.xml").toFile().length());
// Check signature file
- File signatureFile = new File(webAppDir, "META-INF" + File.separator + "signature.SF");
- assertTrue(!signatureFile.exists());
+ Path signatureFile = webAppDir.resolve("META-INF").resolve("signature.SF");
+ assertTrue(Files.notExists(signatureFile));
}
- private void createManifest(File manifest, String... headers) throws Exception {
- try (OutputStream os = new FileOutputStream(manifest); PrintWriter writer = new PrintWriter(os);) {
+ private void createManifest(Path manifest, String... headers) throws Exception {
+ try (PrintWriter writer = new PrintWriter(Files.newOutputStream(manifest));) {
for (String header : headers) {
writer.println(header);
}
diff --git a/org.eclipse.gemini.web.extender/ivy.xml b/org.eclipse.gemini.web.extender/ivy.xml
index e0cba3f..5c28b49 100644
--- a/org.eclipse.gemini.web.extender/ivy.xml
+++ b/org.eclipse.gemini.web.extender/ivy.xml
@@ -18,7 +18,6 @@
<dependencies>
<dependency org="org.eclipse.virgo.util" name="org.eclipse.virgo.util.osgi" rev="${org.eclipse.virgo.util}" conf="compile->runtime"/>
- <dependency org="org.eclipse.virgo.util" name="org.eclipse.virgo.util.io" rev="${org.eclipse.virgo.util}" conf="compile->runtime"/>
<dependency org="org.eclipse.virgo.mirrored" name="org.eclipse.osgi" rev="${org.eclipse.osgi}" conf="compile->compile"/>
<dependency org="javax.servlet" name="javax.servlet" rev="${javax.servlet}" conf="compile->runtime"/>
<dependency org="org.junit" name="com.springsource.org.junit" rev="${org.junit}" conf="test->runtime"/>
diff --git a/org.eclipse.gemini.web.test/.classpath b/org.eclipse.gemini.web.test/.classpath
index 4161732..1157b7f 100644
--- a/org.eclipse.gemini.web.test/.classpath
+++ b/org.eclipse.gemini.web.test/.classpath
@@ -9,7 +9,6 @@
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.eclipse.osgi/3.8.1.v20120830-144521/org.eclipse.osgi-3.8.1.v20120830-144521.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.eclipse.osgi/3.8.1.v20120830-144521/org.eclipse.osgi.source_3.8.1.v20120830-144521.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi/3.6.0.RELEASE/org.eclipse.virgo.util.osgi-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclispe.virgo.util/org.eclipse.virgo.util.osgi/3.6.0.RELEASE/org.eclipse.virgo.util.osgi-sources-3.6.0.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi.manifest/3.6.0.RELEASE/org.eclipse.virgo.util.osgi.manifest-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclispe.virgo.util/org.eclipse.virgo.util.osgi/3.6.0.RELEASE/org.eclipse.virgo.util.osgi-sources-3.6.0.RELEASE.jar"/>
- <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.RELEASE/org.eclipse.virgo.util.io-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclispe.virgo.util/org.eclipse.virgo.util.io/3.6.0.RELEASE/org.eclipse.virgo.util.io-sources-3.6.0.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.common/3.6.0.RELEASE/org.eclipse.virgo.util.common-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclispe.virgo.util/org.eclipse.virgo.util.common/3.6.0.RELEASE/org.eclipse.virgo.util.common-sources-3.6.0.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.parser.launcher/3.6.0.RELEASE/org.eclipse.virgo.util.parser.launcher-3.6.0.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.test/org.eclipse.virgo.test.launcher/3.6.0.RELEASE/org.eclipse.virgo.test.launcher-3.6.0.RELEASE.jar"/>
diff --git a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/FileUtils.java b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/FileUtils.java
new file mode 100644
index 0000000..4f302b7
--- /dev/null
+++ b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/FileUtils.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2015 SAP AG
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * Violeta Georgieva - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.gemini.web.test;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+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.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+public final class FileUtils {
+
+ private FileUtils() {
+ }
+
+ public static boolean deleteDirectory(Path path) {
+ try {
+ Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ });
+ } catch (IOException e) {
+ return false;
+ }
+ return true;
+ }
+
+ public static Path unpackToDir(Path source, Path destination) throws IOException {
+ if (Files.exists(destination)) {
+ deleteDirectory(destination);
+ }
+ Files.createDirectories(destination);
+ try (ZipFile zip = new ZipFile(source.toFile());) {
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ Path entryPath = destination.resolve(entry.getName());
+ if (entry.isDirectory()) {
+ Files.createDirectories(entryPath);
+ } else {
+ Files.createDirectories(entryPath.getParent());
+ Files.copy(zip.getInputStream(entry), entryPath);
+ }
+ }
+ }
+ return destination;
+ }
+
+ public static void copy(Path inPath, Path outPath) throws IOException {
+ try (BufferedReader in = Files.newBufferedReader(inPath, StandardCharsets.UTF_8);
+ BufferedWriter out = Files.newBufferedWriter(outPath, StandardCharsets.UTF_8);) {
+ String line = null;
+ while ((line = in.readLine()) != null) {
+ out.write(line);
+ }
+ out.flush();
+ }
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/extender/ClassPathDependencyTests.java b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/extender/ClassPathDependencyTests.java
index 1eaf2a4..766bd82 100644
--- a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/extender/ClassPathDependencyTests.java
+++ b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/extender/ClassPathDependencyTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,15 +16,15 @@
package org.eclipse.gemini.web.test.extender;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import junit.framework.Assert;
+import org.eclipse.gemini.web.test.FileUtils;
import org.eclipse.virgo.test.framework.OsgiTestRunner;
import org.eclipse.virgo.test.framework.TestFrameworkUtils;
-import org.eclipse.virgo.util.io.JarUtils;
-import org.eclipse.virgo.util.io.PathReference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -36,7 +36,7 @@
@RunWith(OsgiTestRunner.class)
public class ClassPathDependencyTests {
- private static final File WAR_FILE = new File("src/test/resources/classpathdeps.war");
+ private static final Path WAR_FILE = Paths.get("src/test/resources/classpathdeps.war");
private BundleContext context;
@@ -76,25 +76,15 @@
}
private void deployWarDir() throws BundleException, IOException {
- PathReference pr = unpackToDir();
+ Path pr = FileUtils.unpackToDir(WAR_FILE, Paths.get(System.getProperty("java.io.tmpdir"), "unpack-" + System.currentTimeMillis()));
try {
- this.war = this.context.installBundle("webbundle:file:" + pr.getAbsolutePath() + "?Web-ContextPath=/classpathdeps");
+ this.war = this.context.installBundle("webbundle:file:" + pr.toAbsolutePath().toString() + "?Web-ContextPath=/classpathdeps");
this.war.start();
} finally {
- pr.delete(true);
- PathReference tempDir = new PathReference(new File("temp" + File.separator + pr.getName()));
- tempDir.delete(true);
+ Assert.assertTrue(FileUtils.deleteDirectory(Paths.get("temp").resolve(pr.getFileName())));
}
}
- private PathReference unpackToDir() throws IOException {
- String tmpDir = System.getProperty("java.io.tmpdir");
- PathReference dest = new PathReference(new File(tmpDir, "unpack-" + System.currentTimeMillis()));
- PathReference src = new PathReference(WAR_FILE);
- JarUtils.unpackTo(src, dest);
- return dest;
- }
-
private void deployWar() throws BundleException {
this.war = this.context.installBundle("webbundle:file:src/test/resources/classpathdeps.war?Web-ContextPath=/classpathdeps");
this.war.start();
diff --git a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java
index 96ad922..89174ae 100644
--- a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java
+++ b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -24,8 +24,7 @@
import static org.junit.Assert.fail;
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileWriter;
+import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -34,18 +33,19 @@
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Set;
import javax.servlet.ServletContext;
import org.eclipse.gemini.web.core.spi.ServletContainer;
import org.eclipse.gemini.web.core.spi.WebApplicationHandle;
+import org.eclipse.gemini.web.test.FileUtils;
import org.eclipse.virgo.test.framework.OsgiTestRunner;
import org.eclipse.virgo.test.framework.TestFrameworkUtils;
-import org.eclipse.virgo.util.io.FileCopyUtils;
-import org.eclipse.virgo.util.io.FileSystemUtils;
-import org.eclipse.virgo.util.io.PathReference;
-import org.eclipse.virgo.util.io.ZipUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -199,17 +199,16 @@
private void testJSTL(boolean exploded) throws BundleException, MalformedURLException, IOException {
String jstlLocation;
- PathReference unzippedJstl = null;
+ Path unzippedJstl = null;
if (!exploded) {
jstlLocation = "file:" + IVY_CACHE
+ "/repository/org.eclipse.virgo.mirrored/javax.servlet.jsp.jstl/1.2.0.v201105211821/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar";
} else {
String jstlPath = IVY_CACHE
+ "/repository/org.eclipse.virgo.mirrored/javax.servlet.jsp.jstl/1.2.0.v201105211821/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar";
- PathReference jstl = new PathReference(jstlPath);
- unzippedJstl = explode(jstl);
+ unzippedJstl = explode(Paths.get(jstlPath));
- jstlLocation = "file:" + unzippedJstl.getAbsolutePath();
+ jstlLocation = "file:" + unzippedJstl.toAbsolutePath().toString();
}
Bundle jstlBundle = this.bundleContext.installBundle(jstlLocation);
@@ -233,7 +232,7 @@
} finally {
jstlBundle.uninstall();
if (exploded && unzippedJstl != null) {
- unzippedJstl.delete(true);
+ assertTrue(FileUtils.deleteDirectory(unzippedJstl));
}
}
}
@@ -357,9 +356,8 @@
}
}
- private PathReference explode(PathReference packed) throws IOException {
- PathReference target = new PathReference("target");
- return ZipUtils.unzipTo(packed, target);
+ private Path explode(Path packed) throws IOException {
+ return FileUtils.unpackToDir(packed, Paths.get("target/tmp"));
}
@Test
@@ -382,16 +380,16 @@
@Test
public void testWarWithContextXml() throws Exception {
// Copy default context.xml
- File defaultContextXml = new File("target/config/context.xml");
+ Path defaultContextXml = Paths.get("target/config/context.xml");
createFileWithContent(defaultContextXml, "<Context crossContext=\"true\"/>");
// Copy default context.xml.default
- File defaultHostContextXml = new File("target/config/Catalina/localhost/context.xml.default");
+ Path defaultHostContextXml = Paths.get("target/config/Catalina/localhost/context.xml.default");
String content = "<Context>"
+ "<Resource name=\"mail/Session1\" auth=\"Container\" type=\"javax.mail.Session\" mail.smtp.host=\"localhost\"/>" + "</Context>";
createFileWithContent(defaultHostContextXml, content);
- File tomcatServerXml = new File("target/config/tomcat-server.xml");
+ Path tomcatServerXml = Paths.get("target/config/tomcat-server.xml");
createFileWithContent(tomcatServerXml, "");
String location1 = LOCATION_WAR_WITH_CONTEXT_XML_RESOURCES;
@@ -423,33 +421,33 @@
this.container.stopWebApplication(handle2);
bundle2.uninstall();
- assertTrue(defaultContextXml.delete());
- assertTrue(defaultHostContextXml.delete());
- assertTrue(tomcatServerXml.delete());
+ Files.delete(defaultContextXml);
+ Files.delete(defaultHostContextXml);
+ Files.delete(tomcatServerXml);
}
}
@Test
public void testInstallWebAppDir() throws Exception {
// Create web app dir
- File webAppDir = new File("target/test-classes/simple-web-app-dir");
- File indexJsp = new File(webAppDir, "index.jsp");
+ Path webAppDir = Paths.get("target/test-classes/simple-web-app-dir");
+ Path indexJsp = webAppDir.resolve("index.jsp");
createFileWithContent(indexJsp, "Hello World!\n"
+ "config.getServletContext().getResourcePaths(/): <%=config.getServletContext().getResourcePaths(\"/\")%>\n"
+ "config.getServletContext().getRealPath(/): <%=config.getServletContext().getRealPath(\"/\")%>\n"
+ "************** REAL PATH: <%=request.getRealPath(\".\")%>\n"
+ "************** REAL PATH: <%=request.getRealPath(\"META-INF/.\")%>\n");
- File metaInf = new File(webAppDir, "META-INF");
- File manifest = new File(metaInf, "MANIFEST.MF");
+ Path metaInf = webAppDir.resolve("META-INF");
+ Path manifest = metaInf.resolve("MANIFEST.MF");
createFileWithContent(manifest, "");
- File otherMetaInf = new File(webAppDir, "blah/META-INF.");
- File otherManifest = new File(otherMetaInf, "MANIFEST.MF");
+ Path otherMetaInf = webAppDir.resolve("blah/META-INF.");
+ Path otherManifest = otherMetaInf.resolve("MANIFEST.MF");
createFileWithContent(otherManifest, "Manifest-Version: 1.0");
- File otherDirectory = new File(webAppDir, "blah/META-INF.blah");
- File otherStaticResource = new File(otherDirectory, "test.txt");
+ Path otherDirectory = webAppDir.resolve("blah/META-INF.blah");
+ Path otherStaticResource = otherDirectory.resolve("test.txt");
createFileWithContent(otherStaticResource, "TEST");
- Object[] result = startWebApplicationWith(LOCATION_PREFIX + webAppDir.getAbsolutePath() + "?Web-ContextPath=/simple-web-app-dir",
+ Object[] result = startWebApplicationWith(LOCATION_PREFIX + webAppDir.toAbsolutePath().toString() + "?Web-ContextPath=/simple-web-app-dir",
"/simple-web-app-dir");
try {
@@ -460,8 +458,8 @@
} finally {
this.container.stopWebApplication((WebApplicationHandle) result[1]);
((Bundle) result[0]).uninstall();
- FileSystemUtils.deleteRecursively(webAppDir);
- FileSystemUtils.deleteRecursively(new File("temp"));
+ assertTrue(FileUtils.deleteDirectory(webAppDir));
+ assertTrue(FileUtils.deleteDirectory(Paths.get("temp")));
}
}
@@ -537,12 +535,12 @@
@Test
public void testServletContainerWithCustomDefaultWebXml() throws Exception {
- File tomcatServerXml = new File("target/config/tomcat-server.xml");
+ Path tomcatServerXml = Paths.get("target/config/tomcat-server.xml");
createFileWithContent(tomcatServerXml, "");
// In this custom default web.xml the directory listing is enabled
// Thus we will ensure that a custom default web.xml is used
- File defaultWebXml = new File("target/config/web.xml");
+ Path defaultWebXml = Paths.get("target/config/web.xml");
createFileWithContent(
defaultWebXml,
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
@@ -563,19 +561,19 @@
this.container.stopWebApplication((WebApplicationHandle) result[1]);
((Bundle) result[0]).uninstall();
- assertTrue(tomcatServerXml.delete());
- FileCopyUtils.copy(new File("src/test/resources/web.xml"), defaultWebXml);
+ Files.delete(tomcatServerXml);
+ FileUtils.copy(Paths.get("src/test/resources/web.xml"), defaultWebXml);
}
}
@Test
public void testDirectoryListing() throws Exception {
- File tomcatServerXml = new File("target/config/tomcat-server.xml");
+ Path tomcatServerXml = Paths.get("target/config/tomcat-server.xml");
createFileWithContent(tomcatServerXml, "");
// In this custom default web.xml the directory listing is enabled
// Thus we will ensure that a custom default web.xml is used
- File defaultWebXml = new File("target/config/web.xml");
+ Path defaultWebXml = Paths.get("target/config/web.xml");
createFileWithContent(defaultWebXml, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
+ "<web-app xmlns=\"http://java.sun.com/xml/ns/javaee\"\nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ "xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\"\nversion=\"2.5\">\n"
@@ -586,21 +584,21 @@
+ "<servlet-mapping><servlet-name>default</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>");
// Create web app dir
- File webAppDir = new File("target/test-classes/simple-web-app-dir");
- File testFolder = new File(webAppDir, "test");
- File testHtml = new File(testFolder, "test.html");
+ Path webAppDir = Paths.get("target/test-classes/simple-web-app-dir");
+ Path testFolder = webAppDir.resolve("test");
+ Path testHtml = testFolder.resolve("test.html");
createFileWithContent(testHtml, "Hello World!");
- File metaInf = new File(webAppDir, "META-INF");
- File manifest = new File(metaInf, "MANIFEST.MF");
+ Path metaInf = webAppDir.resolve("META-INF");
+ Path manifest = metaInf.resolve("MANIFEST.MF");
createFileWithContent(manifest, "Manifest-Version: 1.0\n" + "Bundle-ManifestVersion: 2\n" + "Web-ContextPath: /simple-web-app-dir\n"
+ "Bundle-SymbolicName: simple-web-app-dir\n\n");
- Object[] result = startWebApplicationWith("reference:file:" + webAppDir.getAbsolutePath(), "/simple-web-app-dir");
+ Object[] result = startWebApplicationWith("reference:file:" + webAppDir.toAbsolutePath().toString(), "/simple-web-app-dir");
try {
validateURL("http://localhost:8080/simple-web-app-dir/test/test.html");
validateURL("http://localhost:8080/simple-web-app-dir/test");
- FileSystemUtils.deleteRecursively(testFolder);
+ assertTrue(FileUtils.deleteDirectory(testFolder));
// there is cacheTTL property which default value is 5s
Thread.sleep(5000);
validateNotFound("http://localhost:8080/simple-web-app-dir/test");
@@ -608,19 +606,19 @@
this.container.stopWebApplication((WebApplicationHandle) result[1]);
((Bundle) result[0]).uninstall();
- FileSystemUtils.deleteRecursively(webAppDir);
- assertTrue(tomcatServerXml.delete());
- FileCopyUtils.copy(new File("src/test/resources/web.xml"), defaultWebXml);
+ assertTrue(FileUtils.deleteDirectory(webAppDir));
+ Files.delete(tomcatServerXml);
+ FileUtils.copy(Paths.get("src/test/resources/web.xml"), defaultWebXml);
}
}
- private void createFileWithContent(File file, String content) throws Exception {
- if (!file.getParentFile().exists()) {
- assertTrue(file.getParentFile().mkdirs());
+ private void createFileWithContent(Path file, String content) throws Exception {
+ if (Files.notExists(file.getParent())) {
+ Files.createDirectories(file.getParent());
}
- try (FileWriter fWriter = new FileWriter(file);) {
- fWriter.write(content);
- fWriter.flush();
+ try (BufferedWriter bWriter = Files.newBufferedWriter(file, StandardCharsets.UTF_8);) {
+ bWriter.write(content);
+ bWriter.flush();
}
}
diff --git a/org.eclipse.gemini.web.test/src/test/resources/META-INF/MANIFEST.MF b/org.eclipse.gemini.web.test/src/test/resources/META-INF/MANIFEST.MF
index d70009e..192a3e6 100644
--- a/org.eclipse.gemini.web.test/src/test/resources/META-INF/MANIFEST.MF
+++ b/org.eclipse.gemini.web.test/src/test/resources/META-INF/MANIFEST.MF
@@ -5,8 +5,7 @@
Bundle-ManifestVersion: 2
Import-Package: javax.servlet;version="0",junit.framework;version="0",
org.eclipse.gemini.web.core.spi;version="0",org.eclipse.virgo.test.fr
- amework;version="0",org.eclipse.virgo.util.io;version="0",org.junit;v
- ersion="0",org.junit.runner;version="0",org.osgi.framework;version="0
- "
+ amework;version="0",org.junit;version="0",org.junit.runner;version="0
+ ",org.osgi.framework;version="0"
Bundle-SymbolicName: org.eclipse.gemini.web.test
diff --git a/org.eclipse.gemini.web.tomcat/.classpath b/org.eclipse.gemini.web.tomcat/.classpath
index b2273f7..bd03038 100644
--- a/org.eclipse.gemini.web.tomcat/.classpath
+++ b/org.eclipse.gemini.web.tomcat/.classpath
@@ -24,7 +24,6 @@
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-4.7.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-sources-4.5.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.eclipse.osgi/3.8.1.v20120830-144521/org.eclipse.osgi-3.8.1.v20120830-144521.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.eclipse.osgi/3.8.1.v20120830-144521/org.eclipse.osgi-sources-3.8.1.v20120830-144521.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi/3.6.0.RELEASE/org.eclipse.virgo.util.osgi-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclispe.virgo.util/org.eclipse.virgo.util.osgi/3.6.0.RELEASE/org.eclipse.virgo.util.osgi-sources-3.6.0.RELEASE.jar"/>
- <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.RELEASE/org.eclipse.virgo.util.io-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.RELEASE/org.eclipse.virgo.util.io-sources-3.6.0.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.common/3.6.0.RELEASE/org.eclipse.virgo.util.common-3.6.0.RELEASE.jar" sourcepath="/IVY_CACHE/org.eclispe.virgo.util/org.eclipse.virgo.util.common/3.6.0.RELEASE/org.eclipse.virgo.util.common-sources-3.6.0.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.slf4j.api/1.7.2.v20121108-1250/org.slf4j.api-1.7.2.v20121108-1250.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.slf4j.api/1.7.2.v20121108-1250/org.slf4j.api-sources-1.7.2.v20121108-1250.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.apache.catalina/7.0.55.v201409050650/org.apache.catalina-7.0.55.v201409050650.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.apache.catalina/7.0.55.v201409050650/org.apache.catalina.source-7.0.55.v201409050650.jar"/>
diff --git a/org.eclipse.gemini.web.tomcat/ivy.xml b/org.eclipse.gemini.web.tomcat/ivy.xml
index 2d0c203..35783d9 100644
--- a/org.eclipse.gemini.web.tomcat/ivy.xml
+++ b/org.eclipse.gemini.web.tomcat/ivy.xml
@@ -18,7 +18,6 @@
<dependencies>
<dependency org="org.eclipse.virgo.util" name="org.eclipse.virgo.util.osgi" rev="${org.eclipse.virgo.util}" conf="compile->runtime"/>
- <dependency org="org.eclipse.virgo.util" name="org.eclipse.virgo.util.io" rev="${org.eclipse.virgo.util}" conf="compile->runtime"/>
<dependency org="org.eclipse.virgo.mirrored" name="org.eclipse.osgi" rev="${org.eclipse.osgi}" conf="compile->compile"/>
<dependency org="javax.servlet" name="javax.servlet" rev="${javax.servlet}" conf="compile->runtime"/>
<dependency org="org.eclipse.virgo.mirrored" name="javax.servlet.jsp" rev="${javax.servlet.jsp}" conf="compile->runtime"/>
diff --git a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/Activator.java b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/Activator.java
index d57fa51..d0a7799 100644
--- a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/Activator.java
+++ b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,6 +16,7 @@
package org.eclipse.gemini.web.tomcat.internal;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Dictionary;
import java.util.Hashtable;
@@ -23,7 +24,6 @@
import org.eclipse.gemini.web.core.WebContainerProperties;
import org.eclipse.gemini.web.core.spi.ServletContainer;
import org.eclipse.gemini.web.tomcat.internal.loading.DirContextURLStreamHandlerService;
-import org.eclipse.virgo.util.io.IOUtils;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -102,11 +102,17 @@
private TomcatServletContainer createContainer(BundleContext context) throws BundleException {
TomcatServletContainerFactory factory = new TomcatServletContainerFactory();
- InputStream configFile = resolveConfigFile(context);
+ InputStream configFile = null;
try {
+ configFile = resolveConfigFile(context);
return factory.createContainer(configFile, context);
} finally {
- IOUtils.closeQuietly(configFile);
+ if (configFile != null) {
+ try {
+ configFile.close();
+ } catch (IOException e) {
+ }
+ }
}
}
diff --git a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/OsgiAwareEmbeddedTomcat.java b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/OsgiAwareEmbeddedTomcat.java
index de33233..eabe0a5 100644
--- a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/OsgiAwareEmbeddedTomcat.java
+++ b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/OsgiAwareEmbeddedTomcat.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -20,6 +20,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
@@ -52,8 +55,6 @@
import org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader;
import org.eclipse.gemini.web.tomcat.internal.support.BundleFileResolverFactory;
import org.eclipse.gemini.web.tomcat.internal.support.PackageAdminBundleDependencyDeterminer;
-import org.eclipse.virgo.util.io.FatalIOException;
-import org.eclipse.virgo.util.io.PathReference;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -334,13 +335,19 @@
if (this.basedir == null) {
// Create a temp dir.
this.basedir = System.getProperty(USER_DIR);
- PathReference home = new PathReference(this.basedir);
- home.createDirectory();
+ Path home = Paths.get(this.basedir);
+ try {
+ Files.createDirectories(home);
+ } catch (IOException e1) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Cannot create directory " + home);
+ }
+ }
if (!home.isAbsolute()) {
try {
- this.basedir = home.getCanonicalPath();
- } catch (FatalIOException e) {
- this.basedir = home.getAbsolutePath();
+ this.basedir = home.toRealPath().toString();
+ } catch (IOException e) {
+ this.basedir = home.toAbsolutePath().toString();
}
}
}
diff --git a/org.eclipse.gemini.web.tomcat/src/main/resources/META-INF/MANIFEST.MF b/org.eclipse.gemini.web.tomcat/src/main/resources/META-INF/MANIFEST.MF
index 4c50ae7..b255adb 100644
--- a/org.eclipse.gemini.web.tomcat/src/main/resources/META-INF/MANIFEST.MF
+++ b/org.eclipse.gemini.web.tomcat/src/main/resources/META-INF/MANIFEST.MF
@@ -27,9 +27,9 @@
g.eclipse.osgi.baseadaptor.bundlefile;version="0";resolution:="option
al",org.eclipse.osgi.framework.adaptor;version="0";resolution:="optio
nal",org.eclipse.osgi.framework.internal.core;version="0";resolution:
- ="optional",org.eclipse.virgo.util.io;version="2.0",org.eclipse.virgo
- .util.osgi;version="2.0",org.osgi.framework;version="0",org.osgi.serv
- ice.packageadmin;version="1.0",org.osgi.service.url;version="1.0",org
- .osgi.util.tracker;version="1.4.0",org.slf4j;version="1.7.2",org.spri
- ngframework.osgi.util;version="1.2.0",org.xml.sax;version="0"
+ ="optional",org.eclipse.virgo.util.osgi;version="2.0",org.osgi.framew
+ ork;version="0",org.osgi.service.packageadmin;version="1.0",org.osgi.
+ service.url;version="1.0",org.osgi.util.tracker;version="1.4.0",org.s
+ lf4j;version="1.7.2",org.springframework.osgi.util;version="1.2.0",or
+ g.xml.sax;version="0"
diff --git a/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocatorTests.java b/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocatorTests.java
index 0db9ec8..7bf9e4f 100644
--- a/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocatorTests.java
+++ b/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocatorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 VMware Inc.
+ * Copyright (c) 2009, 2015 VMware Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -25,13 +25,13 @@
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Vector;
-import org.eclipse.virgo.util.io.IOUtils;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -98,7 +98,12 @@
try {
is = TomcatConfigLocator.resolveConfigFile(mockContext);
} finally {
- IOUtils.closeQuietly(is);
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
}
}