You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/02/13 14:55:25 UTC
[1/6] incubator-taverna-osgi git commit: TAVERNA-893 newer Taverna
parent
Repository: incubator-taverna-osgi
Updated Branches:
refs/heads/master c41687d21 -> c9bdfb595
TAVERNA-893 newer Taverna parent
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/3fd0508d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/3fd0508d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/3fd0508d
Branch: refs/heads/master
Commit: 3fd0508dee6e2192c6e4a215f03eba941289f422
Parents: c41687d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Feb 12 17:46:35 2016 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Feb 12 17:46:35 2016 +0000
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/3fd0508d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2c8460f..f496138 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.taverna</groupId>
<artifactId>taverna-parent</artifactId>
- <version>1-incubating</version>
+ <version>2-incubating-SNAPSHOT</version>
</parent>
<groupId>org.apache.taverna.osgi</groupId>
<artifactId>apache-taverna-osgi</artifactId>
[5/6] incubator-taverna-osgi git commit: TAVERNA-893 Update for API
changes in download-api
Posted by st...@apache.org.
TAVERNA-893 Update for API changes in download-api
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/d01c5ae4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/d01c5ae4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/d01c5ae4
Branch: refs/heads/master
Commit: d01c5ae4f78517d1fbf08f43da42645a1ca951de
Parents: 62171ab
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sat Feb 13 10:50:02 2016 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sat Feb 13 10:50:02 2016 +0000
----------------------------------------------------------------------
.../apache/taverna/plugin/PluginManager.java | 1 +
.../taverna/plugin/impl/PluginManagerImpl.java | 22 ++++++++++----------
.../plugin/impl/PluginSiteManagerImpl.java | 15 ++++++-------
.../plugin/impl/PluginSiteManagerImplTest.java | 14 ++++++-------
4 files changed, 25 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d01c5ae4/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java b/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
index c1a66f9..9a4fd2c 100644
--- a/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
+++ b/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
@@ -17,6 +17,7 @@
package org.apache.taverna.plugin;
import java.io.File;
+import java.nio.file.Path;
import java.util.List;
import org.apache.taverna.plugin.xml.jaxb.PluginVersions;
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d01c5ae4/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginManagerImpl.java b/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginManagerImpl.java
index 923ea40..6ee0adf 100644
--- a/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginManagerImpl.java
+++ b/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginManagerImpl.java
@@ -20,7 +20,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -196,8 +198,8 @@ public class PluginManagerImpl implements PluginManager {
@Override
public Plugin installPlugin(String pluginSiteURL, String pluginFileName) throws PluginException {
- File pluginFile = getPluginFile(pluginSiteURL, pluginFileName);
- return installPlugin(pluginFile);
+ Path pluginFile = getPluginFile(pluginSiteURL, pluginFileName);
+ return installPlugin(pluginFile.toFile());
}
@Override
@@ -367,15 +369,13 @@ public class PluginManagerImpl implements PluginManager {
}
}
- private File getPluginFile(String pluginSiteURL, String pluginFileName) throws PluginException {
- File pluginFile = new File(getPluginDirectory(), pluginFileName);
- String pluginFileURL = pluginSiteURL + "/" + pluginFileName;
+ private Path getPluginFile(String pluginSiteURL, String pluginFileName) throws PluginException {
+ Path pluginFile = getPluginDirectory().resolve(pluginFileName);
+ URI pluginFileURL = URI.create(pluginSiteURL + "/").resolve(pluginFileName);
try {
- downloadManager.download(new URL(pluginFileURL), pluginFile, DIGEST_ALGORITHM);
+ downloadManager.download(pluginFileURL, pluginFile, DIGEST_ALGORITHM);
} catch (DownloadException e) {
throw new PluginException("Error downloading plugin file " + pluginFile, e);
- } catch (MalformedURLException e) {
- throw new PluginException("Invalid plugin file URL " + pluginFileURL, e);
}
return pluginFile;
}
@@ -393,14 +393,14 @@ public class PluginManagerImpl implements PluginManager {
}
}
- private File getPluginDirectory() throws PluginException {
+ private Path getPluginDirectory() throws PluginException {
File systemPluginsDir = applicationConfiguration.getSystemPluginDir();
if (checkPluginDirectory(systemPluginsDir, true)) {
- return systemPluginsDir;
+ return systemPluginsDir.toPath();
}
File userPluginsDir = applicationConfiguration.getUserPluginDir();
if (checkPluginDirectory(userPluginsDir, true)) {
- return userPluginsDir;
+ return userPluginsDir.toPath();
}
throw new PluginException("No plugin directory avaliable");
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d01c5ae4/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java b/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
index 4aa3826..ef66bb0 100644
--- a/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
+++ b/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
@@ -19,6 +19,7 @@ package org.apache.taverna.plugin.impl;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -44,7 +45,6 @@ import org.apache.taverna.profile.xml.jaxb.Updates;
/**
* PluginSiteManager implementation.
*
- * @author David Withers
*/
public class PluginSiteManagerImpl implements PluginSiteManager {
@@ -86,11 +86,11 @@ public class PluginSiteManagerImpl implements PluginSiteManager {
@Override
public PluginSite createPluginSite(URL pluginSiteURL) throws PluginException {
- try {
+ try {
File tempFile = File.createTempFile("plugins", null);
tempFile.deleteOnExit();
- URL pluginFileURL = new URL(pluginSiteURL + "/" + PLUGINS_FILE);
- downloadManager.download(pluginFileURL, tempFile, DIGEST_ALGORITHM);
+ URI pluginFileURL = URI.create(pluginSiteURL + "/").resolve(PLUGINS_FILE);
+ downloadManager.download(pluginFileURL, tempFile.toPath(), DIGEST_ALGORITHM);
return new PluginSiteImpl("", pluginSiteURL.toExternalForm());
} catch (MalformedURLException e) {
throw new PluginException(String.format("Invalid plugin site URL %1$s", pluginSiteURL), e);
@@ -117,17 +117,14 @@ public class PluginSiteManagerImpl implements PluginSiteManager {
public List<PluginVersions> getPlugins(PluginSite pluginSite) throws PluginException {
List<PluginVersions> plugins = new ArrayList<PluginVersions>();
try {
- URL pluginSiteURL = new URL(pluginSite.getUrl() + "/" + PLUGINS_FILE);
+ URI pluginSiteURL = URI.create(pluginSite.getUrl() + "/").resolve(PLUGINS_FILE);
File pluginsFile = new File(getDataDirectory(), PLUGINS_FILE);
- downloadManager.download(pluginSiteURL, pluginsFile, DIGEST_ALGORITHM);
+ downloadManager.download(pluginSiteURL, pluginsFile.toPath(), DIGEST_ALGORITHM);
Plugins pluginsXML = (Plugins) unmarshaller.unmarshal(pluginsFile);
for (PluginVersions plugin : pluginsXML.getPlugin()) {
plugin.setPluginSiteUrl(pluginSite.getUrl());
plugins.add(plugin);
}
- } catch (MalformedURLException e) {
- throw new PluginException(String.format("Plugin site %1$s has an invalid location",
- pluginSite.getName()), e);
} catch (DownloadException e) {
throw new PluginException(String.format("Error downloading from plugin site %1$s",
pluginSite.getName()), e);
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d01c5ae4/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java b/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
index 55328c4..0e3279c 100644
--- a/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
+++ b/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
@@ -16,18 +16,18 @@
*/
package org.apache.taverna.plugin.impl;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
-import java.io.File;
-import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import org.apache.taverna.configuration.app.ApplicationConfiguration;
import org.apache.taverna.download.DownloadException;
import org.apache.taverna.download.DownloadManager;
import org.apache.taverna.plugin.PluginException;
-import org.apache.taverna.plugin.impl.PluginSiteManagerImpl;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -77,7 +77,7 @@ public class PluginSiteManagerImplTest {
@Test
public void testCreatePluginSite() throws Exception {
downloadManager = mock(DownloadManager.class);
- doNothing().when(downloadManager).download(new URL("file:///"), null, "");
+ doNothing().when(downloadManager).download(URI.create("file:///"), null, "");
pluginSiteManager.setDownloadManager(downloadManager);
@@ -88,7 +88,7 @@ public class PluginSiteManagerImplTest {
@Test(expected=PluginException.class)
public void testCreatePluginSiteDownloadException() throws Exception {
downloadManager = mock(DownloadManager.class);
- doThrow(DownloadException.class).when(downloadManager).download(new URL("file:///"), null, "");
+ doThrow(DownloadException.class).when(downloadManager).download(URI.create("file:///"), null, "");
pluginSiteManager.setDownloadManager(downloadManager);
[3/6] incubator-taverna-osgi git commit: TAVERNA-893 USe HTTPClient 4
and MessageDigest
Posted by st...@apache.org.
TAVERNA-893 USe HTTPClient 4 and MessageDigest
Now supports all Java-supported message digests, including
SHA-1 and SHA-256
Local files supported via java.nio Path URIs.
No longer supported are classical URLs
registered with URLConnection, like ftp://
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/8a82204a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/8a82204a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/8a82204a
Branch: refs/heads/master
Commit: 8a82204a930e99c587f5d60c5df2318a2d8290fe
Parents: d6c43d6
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Feb 12 17:47:47 2016 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Feb 12 17:47:47 2016 +0000
----------------------------------------------------------------------
taverna-download-impl/pom.xml | 23 ++-
.../download/impl/DownloadManagerImpl.java | 156 +++++++++++++------
.../download/impl/TestDownloadManagerImpl.java | 30 +++-
3 files changed, 147 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/8a82204a/taverna-download-impl/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-download-impl/pom.xml b/taverna-download-impl/pom.xml
index bc50c70..e81a1aa 100644
--- a/taverna-download-impl/pom.xml
+++ b/taverna-download-impl/pom.xml
@@ -16,7 +16,8 @@
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.taverna.osgi</groupId>
@@ -45,21 +46,33 @@
<artifactId>taverna-download-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
-
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>${commons.io.version}</version>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient-osgi</artifactId>
+ <version>${apache.httpclient.version}</version>
+ </dependency>
+ <dependency>
+ <!-- Needed by httpclient-osgi -->
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore-osgi</artifactId>
+ <version>${apache.httpcore.version}</version>
+ </dependency>
+ <dependency>
+ <!-- Needed by httpclient-osgi -->
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
</dependency>
+
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/8a82204a/taverna-download-impl/src/main/java/org/apache/taverna/download/impl/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-download-impl/src/main/java/org/apache/taverna/download/impl/DownloadManagerImpl.java b/taverna-download-impl/src/main/java/org/apache/taverna/download/impl/DownloadManagerImpl.java
index 7292c8e..fa76723 100644
--- a/taverna-download-impl/src/main/java/org/apache/taverna/download/impl/DownloadManagerImpl.java
+++ b/taverna-download-impl/src/main/java/org/apache/taverna/download/impl/DownloadManagerImpl.java
@@ -16,14 +16,25 @@
*/
package org.apache.taverna.download.impl;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystemNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Locale;
+import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.io.FileUtils;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.VersionInfo;
import org.apache.log4j.Logger;
import org.apache.taverna.download.DownloadException;
import org.apache.taverna.download.DownloadManager;
@@ -33,81 +44,128 @@ import org.apache.taverna.download.DownloadManager;
*/
public class DownloadManagerImpl implements DownloadManager {
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+
private static final int TIMEOUT = Integer.getInteger("taverna.download.timeout.seconds", 30) * 1000;
-
+
private static final Logger logger = Logger.getLogger(DownloadManagerImpl.class);
- public void download(URL source, File destination) throws DownloadException {
+ @Override
+ public void download(URI source, Path destination) throws DownloadException {
download(source, destination, null);
}
- public void download(URL source, File destination, String digestAlgorithm) throws DownloadException {
- // TODO Use MessageDigest when Java 7 available
- if (digestAlgorithm != null && !digestAlgorithm.equals("MD5")) {
- throw new IllegalArgumentException("Only MD5 supported");
- }
- URL digestSource = null;
+ @Override
+ public void download(URI source, Path destination, String digestAlgorithm) throws DownloadException {
+ URI digestSource = null;
if (digestAlgorithm != null) {
- try {
- digestSource = new URL(source.toString() + mapAlgorithmToFileExtension(digestAlgorithm));
- } catch (MalformedURLException e) {
- throw new DownloadException("Error creating digest URL", e);
- }
+ // Note: Will break with ?download=file.xml kind of URLs
+ digestSource = source.resolve(source.getPath() + mapAlgorithmToFileExtension(digestAlgorithm));
}
download(source, destination, digestAlgorithm, digestSource);
}
- public void download(URL source, File destination, String digestAlgorithm, URL digestSource)
+ public String getUserAgent() {
+ Package pack = getClass().getPackage();
+ String httpClientVersion = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client",
+ Request.class);
+ return "Apache-Taverna-OSGi" + "/" + pack.getImplementationVersion() + " (" + httpClientVersion + ")";
+ }
+
+ @Override
+ public void download(URI source, Path destination, String digestAlgorithm, URI digestSource)
throws DownloadException {
- // TODO Use MessageDigest when Java 7 available
- if (digestAlgorithm != null && !digestAlgorithm.equals("MD5")) {
- throw new IllegalArgumentException("Only MD5 supported");
+
+ MessageDigest md = null;
+ if (digestAlgorithm != null) {
+ try {
+ md = MessageDigest.getInstance(digestAlgorithm);
+ } catch (NoSuchAlgorithmException e) {
+ throw new IllegalArgumentException("Unsupported digestAlgorithm: " + digestAlgorithm, e);
+ }
}
+
// download the file
- File tempFile;
+ Path tempFile;
try {
- tempFile = File.createTempFile("DownloadManager", "tmp");
- tempFile.deleteOnExit();
- logger.info(String.format("Downloading %1$s to %2$s", source, tempFile));
- FileUtils.copyURLToFile(source, tempFile, TIMEOUT, TIMEOUT);
- } catch (IOException e) {
- throw new DownloadException(String.format("Error downloading %1$s to %2$s.", source, destination), e);
+ tempFile = Files.createTempFile(destination.getParent(), "." + destination.getFileName(), ".tmp");
+ } catch (IOException e1) {
+ // perhaps a permission problem?
+ throw new DownloadException("Can't create temporary file in folder " + destination.getParent(), e1);
}
+ logger.info(String.format("Downloading %1$s to %2$s", source, tempFile));
+ downloadToFile(source, tempFile);
+
if (digestSource != null) {
// download the digest file
- File digestFile;
+ String expectedDigest;
+ expectedDigest = downloadHash(digestSource).trim().toLowerCase(Locale.ROOT);
+ // check if the digest matches
try {
- digestFile = File.createTempFile("DownloadManager", "tmp");
- digestFile.deleteOnExit();
- logger.info(String.format("Downloading %1$s to %2$s", digestSource, digestFile));
- FileUtils.copyURLToFile(digestSource, digestFile, TIMEOUT, TIMEOUT);
- } catch (IOException e) {
- throw new DownloadException(String.format("Error checking digest for %1$s.", source), e);
- }
- // check the digest matches
- try {
- String digestString1 = DigestUtils.md5Hex(new FileInputStream(tempFile));
- String digestString2 = FileUtils.readFileToString(digestFile);
- if (!digestString1.equals(digestString2)) {
- throw new DownloadException(String.format(
- "Error downloading file: digsests not equal. (%1$s != %2$s)",
- digestString1, digestString2));
+ try (InputStream s = Files.newInputStream(tempFile)) {
+ DigestUtils.updateDigest(md, s);
+ String actualDigest = Hex.encodeHexString(md.digest());
+ if (!actualDigest.equals(expectedDigest)) {
+ throw new DownloadException(
+ String.format("Error downloading file: checksum mismatch (%1$s != %2$s)",
+ actualDigest, expectedDigest));
+ }
}
} catch (IOException e) {
- throw new DownloadException(String.format("Error checking digest for %1$s", destination),
- e);
+ throw new DownloadException(String.format("Error checking digest for %1$s", destination), e);
}
}
- // copy file to destination
+ // All fine, move to destination
try {
logger.info(String.format("Copying %1$s to %2$s", tempFile, destination));
- FileUtils.copyFile(tempFile, destination);
+ Files.move(tempFile, destination, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new DownloadException(String.format("Error downloading %1$s to %2$s.", source, destination), e);
}
}
+ private String downloadHash(URI source) throws DownloadException {
+ try {
+ // We want to handle http/https with HTTPClient
+ if (source.getScheme().equalsIgnoreCase("http") || source.getScheme().equalsIgnoreCase("https")) {
+ logger.info("Downloading checksum " + source);
+ return Request.Get(source).userAgent(getUserAgent()).connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute()
+ .returnContent().asString(StandardCharsets.ISO_8859_1);
+ } else {
+ // Try as a supported Path, e.g. file: or relative path
+ try {
+ Path path = Paths.get(source);
+ return Files.readAllLines(path, StandardCharsets.ISO_8859_1).get(0);
+ } catch (FileSystemNotFoundException e) {
+ throw new DownloadException("Unsupported URL scheme: " + source.getScheme());
+ }
+ }
+ } catch (IOException e) {
+ throw new DownloadException(String.format("Error downloading %1$s", source), e);
+ }
+ }
+
+ private void downloadToFile(URI source, Path destination) throws DownloadException {
+ try {
+ // We want to handle http/https with HTTPClient
+ if (source.getScheme().equalsIgnoreCase("http") || source.getScheme().equalsIgnoreCase("https")) {
+ Request.Get(source).userAgent(getUserAgent()).connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute()
+ .saveContent(destination.toFile());
+ } else {
+ // Try as a supported Path, e.g. file: or relative path
+ try {
+ Path path = Paths.get(source);
+ Files.copy(path, destination, StandardCopyOption.REPLACE_EXISTING);
+ } catch (FileSystemNotFoundException e) {
+ throw new DownloadException("Unsupported URL scheme: " + source.getScheme());
+ }
+ }
+ } catch (IOException e) {
+ throw new DownloadException(String.format("Error downloading %1$s to %2$s.", source, destination), e);
+ }
+ }
+
private String mapAlgorithmToFileExtension(String algorithm) {
return "." + algorithm.toLowerCase().replaceAll("-", "");
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/8a82204a/taverna-download-impl/src/test/java/org/apache/taverna/download/impl/TestDownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-download-impl/src/test/java/org/apache/taverna/download/impl/TestDownloadManagerImpl.java b/taverna-download-impl/src/test/java/org/apache/taverna/download/impl/TestDownloadManagerImpl.java
index a260c59..fbe2dcb 100644
--- a/taverna-download-impl/src/test/java/org/apache/taverna/download/impl/TestDownloadManagerImpl.java
+++ b/taverna-download-impl/src/test/java/org/apache/taverna/download/impl/TestDownloadManagerImpl.java
@@ -3,7 +3,7 @@ package org.apache.taverna.download.impl;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.junit.Assert.assertEquals;
-import java.net.URL;
+import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -15,7 +15,7 @@ public class TestDownloadManagerImpl {
/**
* This test should remain @Ignored
- * as it relies on a third-party web site
+ * as it relies on a web site
* and should not break the build.
*
* Verifies TAVERNA-893
@@ -28,13 +28,13 @@ public class TestDownloadManagerImpl {
Path pomFile = Files.createTempFile("test", ".pom");
// NOTE: The below URL is a Taverna 2 POM - not related to
// taverna-plugin-impl
- URL wrongURL = new URL("http://192.185.115.65/~diana/DIANA_plugin_updated/test-plugins/gr/dianatools/diana.services-activity/1.0-SNAPSHOT/diana.services-activity-1.0-SNAPSHOT.pom");
+ URI wrongURL = URI.create("http://192.185.115.65/~diana/DIANA_plugin_updated/test-plugins/gr/dianatools/diana.services-activity/1.0-SNAPSHOT/diana.services-activity-1.0-SNAPSHOT.pom");
// With this we get an exception - but only because the
// 300 erorr page fails the MD5 check
//dl.download(wrongURL, pomFile.toFile(), "MD5");
// so we'll try without hashsum
- dl.download(wrongURL, pomFile.toFile());
+ dl.download(wrongURL, pomFile);
}
@@ -47,7 +47,7 @@ public class TestDownloadManagerImpl {
*/
@Test
public void downloadLocalFile() throws Exception {
- Path example = Files.createTempFile("example", ".txt");
+ Path example = Files.createTempFile("test", ".txt");
Files.write(example, "Hello world".getBytes(US_ASCII)); // No newline
Path exampleMd5 = example.resolveSibling(example.getFileName() + ".md5");
// stain@biggie:~$ echo -n "Hello world"|md5sum
@@ -58,11 +58,25 @@ public class TestDownloadManagerImpl {
Path toFile = Files.createTempFile("downloaded", ".txt");
- dl.download(example.toUri().toURL(), toFile.toFile(), "MD5");
+ dl.download(example.toUri(), toFile, "MD5");
String hello = Files.readAllLines(toFile, US_ASCII).get(0);
- assertEquals("Hello world", hello);
-
+ assertEquals("Hello world", hello);
+ }
+
+ /**
+ * This test should remain @Ignored
+ * as it relies on a web site
+ * and should not break the build.
+ *
+ */
+ @Ignore
+ @Test
+ public void downloadPomSha1() throws Exception {
+ Path destination = Files.createTempFile("test", "pom");
+ URI source = URI.create("https://repo.maven.apache.org/maven2/org/apache/apache/17/apache-17.pom");
+ DownloadManagerImpl dl = new DownloadManagerImpl();
+ dl.download(source, destination, "SHA-1");
}
}
[2/6] incubator-taverna-osgi git commit: TAVERNA-893 download-api to
Use modern types (URI, Path)
Posted by st...@apache.org.
TAVERNA-893 download-api to Use modern types (URI, Path)
Also removed @author as we don't maintain those under ASF
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/d6c43d6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/d6c43d6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/d6c43d6f
Branch: refs/heads/master
Commit: d6c43d6fa11f33572555b59d8e49fbdc2c7d8ee2
Parents: 3fd0508
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Feb 12 17:46:50 2016 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Feb 12 17:46:50 2016 +0000
----------------------------------------------------------------------
.../org/apache/taverna/download/DownloadManager.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/d6c43d6f/taverna-download-api/src/main/java/org/apache/taverna/download/DownloadManager.java
----------------------------------------------------------------------
diff --git a/taverna-download-api/src/main/java/org/apache/taverna/download/DownloadManager.java b/taverna-download-api/src/main/java/org/apache/taverna/download/DownloadManager.java
index 7992d85..f167596 100644
--- a/taverna-download-api/src/main/java/org/apache/taverna/download/DownloadManager.java
+++ b/taverna-download-api/src/main/java/org/apache/taverna/download/DownloadManager.java
@@ -16,13 +16,12 @@
*/
package org.apache.taverna.download;
-import java.io.File;
-import java.net.URL;
+import java.net.URI;
+import java.nio.file.Path;
/**
* Download Manager for handling file download and checking the integrity of the download.
*
- * @author David Withers
*/
public interface DownloadManager {
@@ -43,7 +42,7 @@ public interface DownloadManager {
* the destination is not a file</li> <li>the destination cannot be written to</li>
* </ul>
*/
- public void download(URL source, File destination) throws DownloadException;
+ public void download(URI source, Path destination) throws DownloadException;
/**
* Downloads a file from a URL and checks the integrity of the download by downloading and
@@ -74,7 +73,7 @@ public interface DownloadManager {
* </li> <li>the destination is not a file</li> <li>the checksums do no match</li>
* </ul>
*/
- public void download(URL source, File destination, String digestAlgorithm)
+ public void download(URI source, Path destination, String digestAlgorithm)
throws DownloadException;
/**
@@ -106,7 +105,7 @@ public interface DownloadManager {
* does not exist</li> <li>the checksums do no match</li>
* </ul>
*/
- public void download(URL source, File destination, String digestAlgorithm, URL digestSource)
+ public void download(URI source, Path destination, String digestAlgorithm, URI digestSource)
throws DownloadException;
}
[6/6] incubator-taverna-osgi git commit: java.net.URL -> java.net.URI
Posted by st...@apache.org.
java.net.URL -> java.net.URI
.. we want to avoid those awkward .equals() errors
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/c9bdfb59
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/c9bdfb59
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/c9bdfb59
Branch: refs/heads/master
Commit: c9bdfb59511ec60bc9c5525fec0d6fe0c1291e59
Parents: d01c5ae
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sat Feb 13 13:54:02 2016 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sat Feb 13 13:54:02 2016 +0000
----------------------------------------------------------------------
.../taverna/plugin/PluginSiteManager.java | 4 +--
.../plugin/impl/PluginSiteManagerImpl.java | 8 ++---
.../plugin/impl/PluginSiteManagerImplTest.java | 5 ++-
.../taverna/update/impl/UpdateManagerImpl.java | 36 ++++++--------------
4 files changed, 16 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/c9bdfb59/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginSiteManager.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginSiteManager.java b/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginSiteManager.java
index ce8ad8e..f6c3d80 100644
--- a/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginSiteManager.java
+++ b/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginSiteManager.java
@@ -16,7 +16,7 @@
*/
package org.apache.taverna.plugin;
-import java.net.URL;
+import java.net.URI;
import java.util.List;
import org.apache.taverna.plugin.xml.jaxb.PluginVersions;
@@ -44,7 +44,7 @@ public interface PluginSiteManager {
* @param pluginSiteURL the plugin site URL
* @throws PluginException if there is a problem contacting the plugin site
*/
- public PluginSite createPluginSite(URL pluginSiteURL) throws PluginException;
+ public PluginSite createPluginSite(URI pluginSiteURL) throws PluginException;
/**
* Adds a plugin site.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/c9bdfb59/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java b/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
index ef66bb0..30daae4 100644
--- a/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
+++ b/taverna-plugin-impl/src/main/java/org/apache/taverna/plugin/impl/PluginSiteManagerImpl.java
@@ -18,9 +18,7 @@ package org.apache.taverna.plugin.impl;
import java.io.File;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -85,15 +83,13 @@ public class PluginSiteManagerImpl implements PluginSiteManager {
}
@Override
- public PluginSite createPluginSite(URL pluginSiteURL) throws PluginException {
+ public PluginSite createPluginSite(URI pluginSiteURL) throws PluginException {
try {
File tempFile = File.createTempFile("plugins", null);
tempFile.deleteOnExit();
URI pluginFileURL = URI.create(pluginSiteURL + "/").resolve(PLUGINS_FILE);
downloadManager.download(pluginFileURL, tempFile.toPath(), DIGEST_ALGORITHM);
- return new PluginSiteImpl("", pluginSiteURL.toExternalForm());
- } catch (MalformedURLException e) {
- throw new PluginException(String.format("Invalid plugin site URL %1$s", pluginSiteURL), e);
+ return new PluginSiteImpl("", pluginSiteURL.toString());
} catch (DownloadException e) {
throw new PluginException(String.format("Error contacting plugin site at %1$s", pluginSiteURL), e);
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/c9bdfb59/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java b/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
index 0e3279c..796ed1d 100644
--- a/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
+++ b/taverna-plugin-impl/src/test/java/org/apache/taverna/plugin/impl/PluginSiteManagerImplTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import java.net.URI;
-import java.net.URL;
import org.apache.taverna.configuration.app.ApplicationConfiguration;
import org.apache.taverna.download.DownloadException;
@@ -81,7 +80,7 @@ public class PluginSiteManagerImplTest {
pluginSiteManager.setDownloadManager(downloadManager);
- pluginSiteManager.createPluginSite(new URL("file:///"));
+ pluginSiteManager.createPluginSite(URI.create("file:///"));
}
@@ -92,7 +91,7 @@ public class PluginSiteManagerImplTest {
pluginSiteManager.setDownloadManager(downloadManager);
- pluginSiteManager.createPluginSite(new URL("file:///"));
+ pluginSiteManager.createPluginSite(URI.create("file:///"));
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/c9bdfb59/taverna-update-impl/src/main/java/org/apache/taverna/update/impl/UpdateManagerImpl.java
----------------------------------------------------------------------
diff --git a/taverna-update-impl/src/main/java/org/apache/taverna/update/impl/UpdateManagerImpl.java b/taverna-update-impl/src/main/java/org/apache/taverna/update/impl/UpdateManagerImpl.java
index 6f6b4b5..136c15b 100644
--- a/taverna-update-impl/src/main/java/org/apache/taverna/update/impl/UpdateManagerImpl.java
+++ b/taverna-update-impl/src/main/java/org/apache/taverna/update/impl/UpdateManagerImpl.java
@@ -18,10 +18,9 @@ package org.apache.taverna.update.impl;
import java.io.File;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.net.URL;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -48,7 +47,6 @@ import org.osgi.service.event.EventAdmin;
/**
* Implementation of the Taverna Update Manager.
*
- * @author David Withers
*/
public class UpdateManagerImpl implements UpdateManager {
@@ -84,13 +82,10 @@ public class UpdateManagerImpl implements UpdateManager {
String version = applicationProfile.getVersion();
Updates updates = applicationProfile.getUpdates();
- URL updatesURL;
+ URI updatesURL;
try {
URI updateSiteURI = new URI(updates.getUpdateSite());
- updatesURL = updateSiteURI.resolve(updates.getUpdatesFile()).toURL();
- } catch (MalformedURLException e) {
- throw new UpdateException(String.format("Update site URL (%s) is not a valid URL",
- updates.getUpdateSite()), e);
+ updatesURL = updateSiteURI.resolve(updates.getUpdatesFile());
} catch (URISyntaxException e) {
throw new UpdateException(String.format("Update site URL (%s) is not a valid URL",
updates.getUpdateSite()), e);
@@ -99,7 +94,7 @@ public class UpdateManagerImpl implements UpdateManager {
updateDirectory.mkdirs();
File updatesFile = new File(updateDirectory, updates.getUpdatesFile());
try {
- downloadManager.download(updatesURL, updatesFile, DIGEST_ALGORITHM);
+ downloadManager.download(updatesURL, updatesFile.toPath(), DIGEST_ALGORITHM);
} catch (DownloadException e) {
throw new UpdateException(String.format("Error downloading %1$s",
updatesURL), e);
@@ -124,14 +119,10 @@ public class UpdateManagerImpl implements UpdateManager {
if (updateAvailable) {
ApplicationProfile applicationProfile = applicationConfiguration.getApplicationProfile();
Updates updates = applicationProfile.getUpdates();
- URL profileURL;
+ URI profileURL;
try {
URI updateSiteURI = new URI(updates.getUpdateSite());
- profileURL = updateSiteURI.resolve(latestVersion.getFile()).toURL();
- } catch (MalformedURLException e) {
- throw new UpdateException(String.format(
- "Application profile URL (%s) is not a valid URL",
- latestVersion.getFile()), e);
+ profileURL = updateSiteURI.resolve(latestVersion.getFile());
} catch (URISyntaxException e) {
throw new UpdateException(String.format("Update site URL (%s) is not a valid URL",
updates.getUpdateSite()), e);
@@ -143,7 +134,7 @@ public class UpdateManagerImpl implements UpdateManager {
File latestProfileFile = new File(updateDirectory, "ApplicationProfile-"
+ latestVersion.getVersion() + ".xml");
try {
- downloadManager.download(profileURL, latestProfileFile, DIGEST_ALGORITHM);
+ downloadManager.download(profileURL, latestProfileFile.toPath(), DIGEST_ALGORITHM);
} catch (DownloadException e) {
throw new UpdateException(String.format("Error downloading %1$s",
profileURL), e);
@@ -195,20 +186,13 @@ public class UpdateManagerImpl implements UpdateManager {
updates.getUpdateSite()), e);
}
for (BundleInfo bundle : requiredBundles) {
- URL bundleURL;
URI bundleURI = updateLibDirectory.resolve(bundle.getFileName());
+ Path bundleDestination = new File(file, bundle.getFileName()).toPath();
try {
- bundleURL = bundleURI.toURL();
- } catch (MalformedURLException e) {
- throw new UpdateException(String.format("Bundle URL (%s) is not a valid URL",
- bundleURI), e);
- }
- File bundleDestination = new File(file, bundle.getFileName());
- try {
- downloadManager.download(bundleURL, new File(file, bundle.getFileName()), DIGEST_ALGORITHM);
+ downloadManager.download(bundleURI, bundleDestination, DIGEST_ALGORITHM);
} catch (DownloadException e) {
throw new UpdateException(String.format("Error downloading %1$s to %2$s",
- bundleURL, bundleDestination), e);
+ bundleURI, bundleDestination), e);
}
}
}
[4/6] incubator-taverna-osgi git commit: org/apache as OSGi Event root
Posted by st...@apache.org.
org/apache as OSGi Event root
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/62171ab7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/62171ab7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/62171ab7
Branch: refs/heads/master
Commit: 62171ab7722830eed04c1cc61db9e988f061ffdb
Parents: 8a82204
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Feb 12 17:51:55 2016 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Feb 12 17:51:55 2016 +0000
----------------------------------------------------------------------
.../src/main/java/org/apache/taverna/plugin/PluginManager.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/62171ab7/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
----------------------------------------------------------------------
diff --git a/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java b/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
index aac1583..c1a66f9 100644
--- a/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
+++ b/taverna-plugin-api/src/main/java/org/apache/taverna/plugin/PluginManager.java
@@ -28,7 +28,7 @@ import org.apache.taverna.plugin.xml.jaxb.PluginVersions;
*/
public interface PluginManager {
- public static final String EVENT_TOPIC_ROOT = "uk/org/taverna/commons/plugin/PluginManager/";
+ public static final String EVENT_TOPIC_ROOT = "org/apache/taverna/plugin/PluginManager/";
public static final String PLUGIN_INSTALLED = EVENT_TOPIC_ROOT + "PLUGIN_INSTALLED";
public static final String PLUGIN_UNINSTALLED = EVENT_TOPIC_ROOT + "PLUGIN_UNINSTALLED";
public static final String UPDATES_AVAILABLE = EVENT_TOPIC_ROOT + "UPDATES_AVAILABLE";