aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2012-09-04 10:53:56 (EDT)
committerThomas Becker2012-09-04 10:53:56 (EDT)
commit1b3d32e33736c3974c9196a8c5ab3ab1ecb7cc01 (patch)
treecee2a3202aeef3fae4cdc473fb3562c24a30f84d
parent0b77a695714de52c156979118d0fe2a6ec29c6b9 (diff)
downloadorg.eclipse.jetty.project-1b3d32e33736c3974c9196a8c5ab3ab1ecb7cc01.zip
org.eclipse.jetty.project-1b3d32e33736c3974c9196a8c5ab3ab1ecb7cc01.tar.gz
org.eclipse.jetty.project-1b3d32e33736c3974c9196a8c5ab3ab1ecb7cc01.tar.bz2
jetty-9 jetty-plugins is now able to handle multiple repositoriesmci
-rw-r--r--jetty-plugins/src/main/java/org/eclipse/jetty/plugins/DefaultPluginManager.java3
-rw-r--r--jetty-plugins/src/main/java/org/eclipse/jetty/plugins/HttpMavenService.java167
-rw-r--r--jetty-plugins/src/main/java/org/eclipse/jetty/plugins/Main.java4
-rw-r--r--jetty-plugins/src/main/java/org/eclipse/jetty/plugins/model/Plugin.java4
-rw-r--r--jetty-plugins/src/main/java/org/eclipse/jetty/plugins/util/MavenUtils.java10
-rw-r--r--jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceIntegrationTest.java7
-rw-r--r--jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceTest.java3
7 files changed, 111 insertions, 87 deletions
diff --git a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/DefaultPluginManager.java b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/DefaultPluginManager.java
index bcf0ac0..9203a6f 100644
--- a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/DefaultPluginManager.java
+++ b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/DefaultPluginManager.java
@@ -89,7 +89,8 @@ public class DefaultPluginManager implements PluginManager
if (zipEntry.isDirectory())
{
// if its a directory, create it
- f.mkdir(); // TODO: check the result: what if the directory cannot be created ?
+ if(!f.mkdir()) // TODO: what if the directory cannot be created?
+ System.out.println("Can't create directory: " + f);
return;
}
diff --git a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/HttpMavenService.java b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/HttpMavenService.java
index d39a1b4..41bdd19 100644
--- a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/HttpMavenService.java
+++ b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/HttpMavenService.java
@@ -38,24 +38,23 @@ import org.eclipse.jetty.plugins.util.StreamUtils;
public class HttpMavenService implements MavenService
{
private static final String REPOSITORY_URL = "http://repo2.maven.org/maven2/";
- // autodetect...without maven deps
- private static final String GROUP_ID = "org/eclipse/jetty";
+ private static final String[] GROUP_IDS = new String[]{"org/eclipse/jetty"};
private static final String VERSION = "9.0.0-SNAPSHOT"; // TODO: should be automatically set
private boolean _searchRemoteRepository = true;
private boolean _searchLocalRepository = false;
private String _localRepository = MavenUtils.getLocalRepositoryLocation();
private String _repositoryUrl = REPOSITORY_URL;
- private String _groupId = GROUP_ID;
+ private String[] _groupIds = GROUP_IDS;
private String _version = VERSION;
public Set<String> listAvailablePlugins()
{
System.out.println("Using local repo: " + _searchLocalRepository + " remote repo: " + _searchRemoteRepository);
Set<String> availablePlugins = new HashSet<>();
- if(_searchRemoteRepository)
+ if (_searchRemoteRepository)
availablePlugins.addAll(getListOfRemotePlugins());
- if(_searchLocalRepository)
+ if (_searchLocalRepository)
availablePlugins.addAll(getListOfLocalPlugins());
return availablePlugins;
@@ -64,21 +63,28 @@ public class HttpMavenService implements MavenService
private Set<String> getListOfLocalPlugins()
{
Set<String> availablePlugins = new HashSet<>();
- File localMavenRepository = new File(_localRepository + _groupId);
- if(!localMavenRepository.exists())
+ File localMavenRepository = new File(_localRepository);
+ if (!localMavenRepository.exists())
{
System.out.println("Can't find local repo: " + localMavenRepository);
return availablePlugins;
}
System.out.println("Using local repository: " + localMavenRepository);
- String[] localMavenModuleList = localMavenRepository.list();
- for (String potentialPlugin : localMavenModuleList)
+ for (String groupId : _groupIds)
{
- File pluginFile = new File(_localRepository + getPluginPath(potentialPlugin));
- if(pluginFile.exists())
- availablePlugins.add(potentialPlugin);
+ File file = new File(_localRepository + groupId);
+ if (!file.exists())
+ break;
+
+ String[] localMavenModuleList = file.list();
+ for (String potentialPlugin : localMavenModuleList)
+ {
+ File pluginFile = new File(_localRepository + getPluginPath(groupId,potentialPlugin));
+ if (pluginFile.exists())
+ availablePlugins.add(potentialPlugin);
+ }
}
return availablePlugins;
@@ -107,10 +113,15 @@ public class HttpMavenService implements MavenService
{
try
{
- URL url = new URL(_repositoryUrl + _groupId);
- URLConnection connection = url.openConnection();
- InputStream inputStream = connection.getInputStream();
- return StreamUtils.inputStreamToString(inputStream);
+ StringBuilder directoryListing = new StringBuilder();
+ for (String groupId : _groupIds)
+ {
+ URL url = new URL(_repositoryUrl + groupId);
+ URLConnection connection = url.openConnection();
+ InputStream inputStream = connection.getInputStream();
+ directoryListing.append(StreamUtils.inputStreamToString(inputStream));
+ }
+ return directoryListing.toString();
}
catch (IOException e)
{
@@ -120,83 +131,99 @@ public class HttpMavenService implements MavenService
private String fetchModuleDirectoryListing(String module)
{
- try
- {
- URL configJar = new URL(getRemoteModuleDirectory(module));
- URLConnection connection = configJar.openConnection();
- InputStream inputStream = connection.getInputStream();
- return StreamUtils.inputStreamToString(inputStream);
- }
- catch (MalformedURLException e)
- {
- throw new IllegalStateException(e);
- }
- catch (IOException e)
+ for (String groupId : _groupIds)
{
- // Honestly, I'm not a friend of ignoring exceptions as it might
- // hide something important. In this case however it "usually"
- // just means: THIS IS NOT A PLUGIN! However it still might hide
- // things. If that'll be the case, I hope I'm not the one who
- // has to debug my own code. ;)
- return "not a plugin";
+ try
+ {
+ URL configJar = new URL(_repositoryUrl + getModulePath(groupId, module));
+ URLConnection connection = configJar.openConnection();
+ InputStream inputStream = connection.getInputStream();
+ return StreamUtils.inputStreamToString(inputStream);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalStateException(e);
+ }
+ catch (IOException e)
+ {
+ // Honestly, I'm not a friend of ignoring exceptions as it might
+ // hide something important. In this case however it "usually"
+ // just means: THIS IS NOT A PLUGIN! However it still might hide
+ // things. If that'll be the case, I hope I'm not the one who
+ // has to debug my own code. ;)
+ System.out.println(e); //TODO:
+ }
}
+ return "not a plugin";
}
public Plugin getPlugin(String pluginName)
{
- File configJar = getFile(getRemotePluginLocation(pluginName));
- return new Plugin(pluginName, configJar);
+ File pluginJar = getPluginFile(pluginName);
+ return new Plugin(pluginName, pluginJar);
}
- private String getRemoteModuleDirectory(String pluginName)
+ private String getPluginPath(String groupId, String pluginName)
{
- return _repositoryUrl + getModulePath(pluginName);
+ return getModulePath(groupId, pluginName) + pluginName + "-" + _version + "-plugin.zip";
}
- private String getRemotePluginLocation(String pluginName)
+ private String getModulePath(String groupId, String pluginName)
{
- return _repositoryUrl + getPluginPath(pluginName);
+ return groupId + "/" + pluginName + "/" + _version
+ + "/";
}
- private String getPluginPath(String pluginName)
+ /**
+ * Tries to find the plugin in the local repo first and then tries the remote repositories in the order they're
+ * stored in _repositoryUrls
+ *
+ * @param pluginName the name of the plugin to get the plugin file for
+ * @return the plugin file
+ */
+ private File getPluginFile(String pluginName)
{
- return getModulePath(pluginName) + pluginName + "-" + _version + "-plugin.zip";
- }
+ for (String groupId : _groupIds)
+ {
+ File pluginFile = new File(MavenUtils.getLocalRepositoryLocation() + getPluginPath(groupId, pluginName));
+ if (pluginFile.exists())
+ return pluginFile;
- private String getModulePath(String pluginName)
- {
- return _groupId + "/" + pluginName + "/" + _version
- + "/";
+ String urlString = _repositoryUrl + getPluginPath(groupId, pluginName);
+ String fileName = urlString.substring(urlString.lastIndexOf("/") + 1);
+ try
+ {
+ return getPluginFileFromRemoteLocation(urlString, fileName);
+ }
+ catch (IOException e)
+ {
+ System.out.println("Couldn't find plugin: " + pluginName + " at repo: " + _repositoryUrl + ". " +
+ "Probably trying other repo. Reason: " + e.getMessage());
+ }
+ }
+ throw new IllegalStateException("Plugin: " + pluginName + " not found at any configured repo.");
}
- private File getFile(String urlString)
+ private File getPluginFileFromRemoteLocation(String urlString, String fileName) throws IOException
{
- String fileName = urlString.substring(urlString.lastIndexOf("/") + 1);
- try
- {
- URL url = new URL(urlString);
- URLConnection connection = url.openConnection();
- InputStream inputStream = connection.getInputStream();
- File tempFile = new File(System.getProperty("java.io.tmpdir"),
- fileName);
- OutputStream out = new FileOutputStream(tempFile);
- byte buf[] = new byte[1024];
- int len;
- while ((len = inputStream.read(buf)) > 0)
- out.write(buf, 0, len);
- out.close();
- inputStream.close();
- return tempFile;
- }
- catch (IOException e)
- {
- throw new IllegalStateException(e);
- }
+ URL url = new URL(urlString);
+ URLConnection connection = url.openConnection();
+ InputStream inputStream = connection.getInputStream();
+ File tempFile = new File(System.getProperty("java.io.tmpdir"),
+ fileName);
+ OutputStream out = new FileOutputStream(tempFile);
+ byte buf[] = new byte[1024];
+ int len;
+ while ((len = inputStream.read(buf)) > 0)
+ out.write(buf, 0, len);
+ out.close();
+ inputStream.close();
+ return tempFile;
}
public void setGroupId(String groupId)
{
- this._groupId = groupId.replace(".", "/");
+ this._groupIds = new String[] { groupId.replace(".", "/") };
}
public void setLocalRepository(String localRepository)
diff --git a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/Main.java b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/Main.java
index 6367715..25d1863 100644
--- a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/Main.java
+++ b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/Main.java
@@ -106,9 +106,9 @@ public class Main
if (arg.startsWith("--version="))
_version = arg.substring(10);
if (arg.startsWith("--useLocalRepo="))
- _searchLocalRepository = new Boolean(arg.substring(15));
+ _searchLocalRepository = Boolean.valueOf(arg.substring(15));
if (arg.startsWith("--useRemoteRepo="))
- _searchRemoteRepository = new Boolean(arg.substring(15));
+ _searchRemoteRepository = Boolean.valueOf(arg.substring(15));
if (arg.startsWith("install"))
_installPlugin = args[i];
if ("list".equals(arg))
diff --git a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/model/Plugin.java b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/model/Plugin.java
index b784053..4225097 100644
--- a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/model/Plugin.java
+++ b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/model/Plugin.java
@@ -25,10 +25,10 @@ public class Plugin
private final String name;
private final File pluginJar;
- public Plugin(String name, File configJar)
+ public Plugin(String name, File pluginJar)
{
this.name = name;
- this.pluginJar = configJar;
+ this.pluginJar = pluginJar;
}
public String getName()
diff --git a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/util/MavenUtils.java b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/util/MavenUtils.java
index 3e153ce..87339bd 100644
--- a/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/util/MavenUtils.java
+++ b/jetty-plugins/src/main/java/org/eclipse/jetty/plugins/util/MavenUtils.java
@@ -26,7 +26,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
public class MavenUtils
{
- private final static String DEFAULT_REPOSITORY_LOCATION = System.getProperty("user.home") + "/.m2/repository";
+ private final static String DEFAULT_REPOSITORY_LOCATION = System.getProperty("user.home") + "/.m2/repository/";
/**
* Looks for maven's settings.xml in $M2_HOME/conf/settings.xml
@@ -36,8 +36,7 @@ public class MavenUtils
static File findGlobalSettingsXml()
{
String m2Home = System.getenv("M2_HOME");
- File settingsXml = new File(m2Home + "/conf/settings.xml");
- return settingsXml;
+ return new File(m2Home + "/conf/settings.xml");
}
/**
@@ -48,8 +47,7 @@ public class MavenUtils
static File findUserSettingsXml()
{
String userHome = System.getProperty("user.home");
- File settingsXml = new File(userHome + "/.m2/settings.xml");
- return settingsXml;
+ return new File(userHome + "/.m2/settings.xml");
}
/**
@@ -146,7 +144,7 @@ public class MavenUtils
}
@Override
- public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
{
}
diff --git a/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceIntegrationTest.java b/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceIntegrationTest.java
index 01c6ba3e..bd5dbb4 100644
--- a/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceIntegrationTest.java
+++ b/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceIntegrationTest.java
@@ -34,9 +34,8 @@ import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/**
- * This is currently more an integration test downloading real stuff from real
- * maven repositories. Actually it's preferred to have a real unit test or at
- * least a local repository server. But since HttpClient.send(exchange) has an
+ * This is currently more an integration test downloading real stuff from real maven repositories. Actually it's
+ * preferred to have a real unit test or at least a local repository server. But since HttpClient.send(exchange) has an
* api which is really hard to mock, I will leave that exercise for later.
* <p/>
* However this tests should be disabled for the general build and ci.
@@ -52,7 +51,7 @@ public class HttpMavenServiceIntegrationTest
@Before
public void setUp() throws Exception
{
- _mavenService.setRepositoryUrl(PRIVATE_NEXUS_REPOSITORY_URL);
+ _mavenService.setRepositoryUrls(new String[]{PRIVATE_NEXUS_REPOSITORY_URL});
}
@Test
diff --git a/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceTest.java b/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceTest.java
index e2b0d22..d665dc6 100644
--- a/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceTest.java
+++ b/jetty-plugins/src/test/java/org/eclipse/jetty/plugins/HttpMavenServiceTest.java
@@ -32,14 +32,13 @@ public class HttpMavenServiceTest
{
private HttpMavenService _mavenService = new HttpMavenService();
- private static final String JETTY_JMX_PLUGIN_NAME = "jetty-jmx";
private static final String MAVEN_CENTRAL_URL = "http://repo2.maven.org/maven2/";
@Before
public void setUp() throws Exception
{
_mavenService.setLocalRepository(this.getClass().getClassLoader().getResource("maven_repo").getFile() + "/");
- _mavenService.setRepositoryUrl(MAVEN_CENTRAL_URL);
+ _mavenService.setRepositoryUrls(new String[]{MAVEN_CENTRAL_URL});
_mavenService.setVersion("version");
_mavenService.setSearchRemoteRepository(false);
_mavenService.setSearchLocalRepository(true);