jetty-9 jetty-plugins now uses zip instead of jar files. Local maven repository is now being read and found located by settings.xml or default location. small improvements
This commit is contained in:
parent
d18fcc05e3
commit
694a07dac6
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.plugins.impl;
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -25,27 +25,26 @@ import java.io.InputStream;
|
|||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.eclipse.jetty.plugins.MavenService;
|
||||
import org.eclipse.jetty.plugins.PluginManager;
|
||||
import org.eclipse.jetty.plugins.model.Plugin;
|
||||
|
||||
public class PluginManagerImpl implements PluginManager
|
||||
public class DefaultPluginManager implements PluginManager
|
||||
{
|
||||
private String _jettyHome;
|
||||
private MavenService _mavenService;
|
||||
|
||||
private static List<String> excludes = Arrays.asList("META-INF");
|
||||
|
||||
public PluginManagerImpl(MavenService mavenService, String jettyHome)
|
||||
public DefaultPluginManager(MavenService mavenService, String jettyHome)
|
||||
{
|
||||
this._mavenService = mavenService;
|
||||
this._jettyHome = jettyHome;
|
||||
}
|
||||
|
||||
public List<String> listAvailablePlugins()
|
||||
public Set<String> listAvailablePlugins()
|
||||
{
|
||||
return _mavenService.listAvailablePlugins();
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ public class PluginManagerImpl implements PluginManager
|
|||
{
|
||||
try
|
||||
{
|
||||
JarFile pluginJar = new JarFile(plugin.getPluginJar());
|
||||
ZipFile pluginJar = new ZipFile(plugin.getPluginJar());
|
||||
extractJar(pluginJar);
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -70,24 +69,24 @@ public class PluginManagerImpl implements PluginManager
|
|||
}
|
||||
}
|
||||
|
||||
private void extractJar(JarFile file)
|
||||
private void extractJar(ZipFile file)
|
||||
{
|
||||
Enumeration<JarEntry> entries = file.entries();
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
extractFileFromJar(file, entries.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
private void extractFileFromJar(JarFile jarFile, JarEntry jarEntry)
|
||||
private void extractFileFromJar(ZipFile zipFile, ZipEntry zipEntry)
|
||||
{
|
||||
for (String exclude : excludes)
|
||||
if (jarEntry.getName().startsWith(exclude))
|
||||
if (zipEntry.getName().startsWith(exclude))
|
||||
return;
|
||||
|
||||
System.out.println("Extracting: " + jarEntry.getName());
|
||||
File f = new File(_jettyHome + File.separator + jarEntry.getName());
|
||||
if (jarEntry.isDirectory())
|
||||
System.out.println("Extracting: " + zipEntry.getName());
|
||||
File f = new File(_jettyHome + File.separator + zipEntry.getName());
|
||||
if (zipEntry.isDirectory())
|
||||
{
|
||||
// if its a directory, create it
|
||||
f.mkdir(); // TODO: check the result: what if the directory cannot be created ?
|
||||
|
@ -95,7 +94,7 @@ public class PluginManagerImpl implements PluginManager
|
|||
}
|
||||
|
||||
|
||||
try (InputStream is = jarFile.getInputStream(jarEntry);
|
||||
try (InputStream is = zipFile.getInputStream(zipEntry);
|
||||
FileOutputStream fos = new FileOutputStream(f))
|
||||
{
|
||||
while (is.available() > 0)
|
||||
|
@ -105,7 +104,7 @@ public class PluginManagerImpl implements PluginManager
|
|||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new IllegalStateException("Could not extract plugin jar", e);
|
||||
throw new IllegalStateException("Could not extract plugin zip", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.plugins.impl;
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -26,26 +26,67 @@ import java.io.OutputStream;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.plugins.MavenService;
|
||||
import org.eclipse.jetty.plugins.model.Plugin;
|
||||
import org.eclipse.jetty.plugins.util.MavenUtils;
|
||||
import org.eclipse.jetty.plugins.util.RepositoryParser;
|
||||
import org.eclipse.jetty.plugins.util.StreamUtils;
|
||||
|
||||
public class HttpMavenServiceImpl implements MavenService
|
||||
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 VERSION = "7.6.0.v20120127"; // TODO: should be automatically set
|
||||
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 _version = VERSION;
|
||||
|
||||
public List<String> listAvailablePlugins()
|
||||
public Set<String> listAvailablePlugins()
|
||||
{
|
||||
List<String> availablePlugins = new ArrayList<>();
|
||||
System.out.println("Using local repo: " + _searchLocalRepository + " remote repo: " + _searchRemoteRepository);
|
||||
Set<String> availablePlugins = new HashSet<>();
|
||||
if(_searchRemoteRepository)
|
||||
availablePlugins.addAll(getListOfRemotePlugins());
|
||||
|
||||
if(_searchLocalRepository)
|
||||
availablePlugins.addAll(getListOfLocalPlugins());
|
||||
|
||||
return availablePlugins;
|
||||
}
|
||||
|
||||
private Set<String> getListOfLocalPlugins()
|
||||
{
|
||||
Set<String> availablePlugins = new HashSet<>();
|
||||
File localMavenRepository = new File(_localRepository + _groupId);
|
||||
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)
|
||||
{
|
||||
File pluginFile = new File(_localRepository + getPluginPath(potentialPlugin));
|
||||
if(pluginFile.exists())
|
||||
availablePlugins.add(potentialPlugin);
|
||||
}
|
||||
|
||||
return availablePlugins;
|
||||
}
|
||||
|
||||
private Set<String> getListOfRemotePlugins()
|
||||
{
|
||||
Set<String> availablePlugins = new HashSet<>();
|
||||
|
||||
String moduleListing = fetchDirectoryListingOfJettyModules();
|
||||
List<String> modules = RepositoryParser
|
||||
|
@ -59,7 +100,6 @@ public class HttpMavenServiceImpl implements MavenService
|
|||
availablePlugins.add(module);
|
||||
}
|
||||
}
|
||||
|
||||
return availablePlugins;
|
||||
}
|
||||
|
||||
|
@ -82,7 +122,7 @@ public class HttpMavenServiceImpl implements MavenService
|
|||
{
|
||||
try
|
||||
{
|
||||
URL configJar = new URL(getModuleDirectory(module));
|
||||
URL configJar = new URL(getRemoteModuleDirectory(module));
|
||||
URLConnection connection = configJar.openConnection();
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
return StreamUtils.inputStreamToString(inputStream);
|
||||
|
@ -104,19 +144,29 @@ public class HttpMavenServiceImpl implements MavenService
|
|||
|
||||
public Plugin getPlugin(String pluginName)
|
||||
{
|
||||
File configJar = getFile(getModulePrefix(pluginName) + "-plugin.jar");
|
||||
File configJar = getFile(getRemotePluginLocation(pluginName));
|
||||
return new Plugin(pluginName, configJar);
|
||||
}
|
||||
|
||||
private String getModuleDirectory(String pluginName)
|
||||
private String getRemoteModuleDirectory(String pluginName)
|
||||
{
|
||||
return _repositoryUrl + _groupId + "/" + pluginName + "/" + _version
|
||||
+ "/";
|
||||
return _repositoryUrl + getModulePath(pluginName);
|
||||
}
|
||||
|
||||
private String getModulePrefix(String pluginName)
|
||||
private String getRemotePluginLocation(String pluginName)
|
||||
{
|
||||
return getModuleDirectory(pluginName) + pluginName + "-" + _version;
|
||||
return _repositoryUrl + getPluginPath(pluginName);
|
||||
}
|
||||
|
||||
private String getPluginPath(String pluginName)
|
||||
{
|
||||
return getModulePath(pluginName) + pluginName + "-" + _version + "-plugin.zip";
|
||||
}
|
||||
|
||||
private String getModulePath(String pluginName)
|
||||
{
|
||||
return _groupId + "/" + pluginName + "/" + _version
|
||||
+ "/";
|
||||
}
|
||||
|
||||
private File getFile(String urlString)
|
||||
|
@ -149,6 +199,11 @@ public class HttpMavenServiceImpl implements MavenService
|
|||
this._groupId = groupId.replace(".", "/");
|
||||
}
|
||||
|
||||
public void setLocalRepository(String localRepository)
|
||||
{
|
||||
this._localRepository = localRepository;
|
||||
}
|
||||
|
||||
public void setRepositoryUrl(String repositoryUrl)
|
||||
{
|
||||
this._repositoryUrl = repositoryUrl;
|
||||
|
@ -158,4 +213,14 @@ public class HttpMavenServiceImpl implements MavenService
|
|||
{
|
||||
this._version = version;
|
||||
}
|
||||
|
||||
public void setSearchRemoteRepository(boolean searchRemoteRepository)
|
||||
{
|
||||
this._searchRemoteRepository = searchRemoteRepository;
|
||||
}
|
||||
|
||||
public void setSearchLocalRepository(boolean searchLocalRepository)
|
||||
{
|
||||
this._searchLocalRepository = searchLocalRepository;
|
||||
}
|
||||
}
|
|
@ -18,17 +18,14 @@
|
|||
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.plugins.impl.HttpMavenServiceImpl;
|
||||
import org.eclipse.jetty.plugins.impl.PluginManagerImpl;
|
||||
import java.util.Set;
|
||||
|
||||
public class Main
|
||||
{
|
||||
private static final String JETTY_HOME = "JETTY_HOME";
|
||||
|
||||
private MavenService _mavenService = new HttpMavenServiceImpl();
|
||||
private MavenService _mavenService = new HttpMavenService();
|
||||
private PluginManager _pluginManager;
|
||||
private String _jettyHome;
|
||||
private String _installPlugin;
|
||||
|
@ -36,6 +33,8 @@ public class Main
|
|||
private String _repositoryUrl;
|
||||
private String _groupId;
|
||||
private String _version;
|
||||
private boolean _searchRemoteRepository = true;
|
||||
private boolean _searchLocalRepository = false;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
@ -49,41 +48,32 @@ public class Main
|
|||
parseCommandline(args);
|
||||
configureMavenService();
|
||||
|
||||
_pluginManager = new PluginManagerImpl(_mavenService, _jettyHome);
|
||||
_pluginManager = new DefaultPluginManager(_mavenService, _jettyHome);
|
||||
|
||||
if (_listPlugins)
|
||||
{
|
||||
listPlugins();
|
||||
}
|
||||
else if (_installPlugin != null)
|
||||
{
|
||||
installPlugin();
|
||||
}
|
||||
}
|
||||
|
||||
private void configureMavenService()
|
||||
{
|
||||
if (_repositoryUrl != null)
|
||||
{
|
||||
_mavenService.setRepositoryUrl(_repositoryUrl);
|
||||
}
|
||||
if (_groupId != null)
|
||||
{
|
||||
_mavenService.setGroupId(_groupId);
|
||||
}
|
||||
if (_version != null)
|
||||
{
|
||||
_mavenService.setVersion(_version);
|
||||
}
|
||||
|
||||
_mavenService.setSearchLocalRepository(_searchLocalRepository);
|
||||
_mavenService.setSearchRemoteRepository(_searchRemoteRepository);
|
||||
}
|
||||
|
||||
private void listPlugins()
|
||||
{
|
||||
List<String> availablePlugins = _pluginManager.listAvailablePlugins();
|
||||
Set<String> availablePlugins = _pluginManager.listAvailablePlugins();
|
||||
for (String pluginName : availablePlugins)
|
||||
{
|
||||
System.out.println(pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
private void installPlugin()
|
||||
|
@ -97,9 +87,7 @@ public class Main
|
|||
{
|
||||
Map<String, String> env = System.getenv();
|
||||
if (env.containsKey(JETTY_HOME))
|
||||
{
|
||||
_jettyHome = env.get(JETTY_HOME);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCommandline(String[] args)
|
||||
|
@ -110,40 +98,36 @@ public class Main
|
|||
i++;
|
||||
|
||||
if (arg.startsWith("--jettyHome="))
|
||||
{
|
||||
_jettyHome = arg.substring(12);
|
||||
}
|
||||
if (arg.startsWith("--repositoryUrl="))
|
||||
{
|
||||
_repositoryUrl = arg.substring(16);
|
||||
}
|
||||
if (arg.startsWith("--groupId="))
|
||||
{
|
||||
_groupId = arg.substring(10);
|
||||
}
|
||||
if (arg.startsWith("--version="))
|
||||
{
|
||||
_version = arg.substring(10);
|
||||
}
|
||||
if (arg.startsWith("--useLocalRepo="))
|
||||
_searchLocalRepository = new Boolean(arg.substring(15));
|
||||
if (arg.startsWith("--useRemoteRepo="))
|
||||
_searchRemoteRepository = new Boolean(arg.substring(15));
|
||||
if (arg.startsWith("install"))
|
||||
{
|
||||
_installPlugin = args[i];
|
||||
}
|
||||
if ("list".equals(arg))
|
||||
{
|
||||
_listPlugins = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Usage instead of throwing exceptions
|
||||
if (_jettyHome == null && _installPlugin != null)
|
||||
throw new IllegalArgumentException(
|
||||
"No --jettyHome commandline option specified and no \"JETTY_HOME\" environment variable found!");
|
||||
printUsage("No --jettyHome commandline option specified and no \"JETTY_HOME\" environment variable found!");
|
||||
if (_installPlugin == null && !_listPlugins)
|
||||
throw new IllegalArgumentException(
|
||||
"Neither install <pluginname> nor list commandline option specified. Nothing to do for me!");
|
||||
printUsage("Neither install <pluginname> nor list commandline option specified. Nothing to do for me!");
|
||||
if (_installPlugin != null && _listPlugins)
|
||||
throw new IllegalArgumentException(
|
||||
"Please specify either install <pluginname> or list commandline options, but not both at the same time!");
|
||||
printUsage("Please specify either install <pluginname> or list commandline options, " +
|
||||
"but not both at the same time!");
|
||||
}
|
||||
|
||||
private void printUsage(String errorMessage)
|
||||
{
|
||||
System.out.println(errorMessage);
|
||||
|
||||
//TODO: print usage
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.plugins.model.Plugin;
|
||||
|
||||
public interface MavenService
|
||||
{
|
||||
public List<String> listAvailablePlugins();
|
||||
public Set<String> listAvailablePlugins();
|
||||
|
||||
public Plugin getPlugin(String pluginName);
|
||||
|
||||
|
@ -33,4 +33,8 @@ public interface MavenService
|
|||
public void setRepositoryUrl(String repositoryUrl);
|
||||
|
||||
public void setVersion(String version);
|
||||
|
||||
public void setSearchLocalRepository(boolean searchLocalRepository);
|
||||
|
||||
public void setSearchRemoteRepository(boolean searchRemoteRepository);
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface PluginManager
|
||||
{
|
||||
public List<String> listAvailablePlugins();
|
||||
public Set<String> listAvailablePlugins();
|
||||
|
||||
public void installPlugin(String pluginName);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
//========================================================================
|
||||
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//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
|
||||
//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.
|
||||
//========================================================================
|
||||
package org.eclipse.jetty.plugins.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
public class MavenUtils
|
||||
{
|
||||
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
|
||||
*
|
||||
* @return a file representing the global settings.xml
|
||||
*/
|
||||
static File findGlobalSettingsXml()
|
||||
{
|
||||
String m2Home = System.getenv("M2_HOME");
|
||||
File settingsXml = new File(m2Home + "/conf/settings.xml");
|
||||
return settingsXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for maven's settings.xml in ${user.home}/.m2/settings.xml
|
||||
*
|
||||
* @return a file representing the user's settings.xml
|
||||
*/
|
||||
static File findUserSettingsXml()
|
||||
{
|
||||
String userHome = System.getProperty("user.home");
|
||||
File settingsXml = new File(userHome + "/.m2/settings.xml");
|
||||
return settingsXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the local repository location from settings.xml. A setting in the user's settings.xml will override the
|
||||
* global one.
|
||||
*
|
||||
* @return location of the local maven repo
|
||||
*/
|
||||
public static String getLocalRepositoryLocation()
|
||||
{
|
||||
String repositoryLocation = DEFAULT_REPOSITORY_LOCATION;
|
||||
try
|
||||
{
|
||||
// find the global setting
|
||||
String tempRepositoryLocation = parseSettingsXml(findGlobalSettingsXml());
|
||||
if (tempRepositoryLocation != null)
|
||||
repositoryLocation = tempRepositoryLocation;
|
||||
|
||||
// override with user settings.xml
|
||||
tempRepositoryLocation = parseSettingsXml(findUserSettingsXml());
|
||||
if (tempRepositoryLocation != null)
|
||||
repositoryLocation = tempRepositoryLocation;
|
||||
}
|
||||
catch (IOException | SAXException e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return repositoryLocation;
|
||||
}
|
||||
|
||||
private static String parseSettingsXml(File settingsXml) throws IOException, SAXException
|
||||
{
|
||||
if(!settingsXml.exists())
|
||||
return null;
|
||||
|
||||
// readability is more important than efficiency here, so we just recreate those objects
|
||||
XMLReader reader = XMLReaderFactory.createXMLReader();
|
||||
SettingsXmlContentHandler settingsXmlContentHandler = new SettingsXmlContentHandler();
|
||||
reader.setContentHandler(settingsXmlContentHandler);
|
||||
|
||||
InputSource source = new InputSource(new FileReader(settingsXml));
|
||||
reader.parse(source);
|
||||
return settingsXmlContentHandler.getRepositoryLocation();
|
||||
}
|
||||
|
||||
private static class SettingsXmlContentHandler implements ContentHandler
|
||||
{
|
||||
private String repositoryLocation;
|
||||
private String currentValue;
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException
|
||||
{
|
||||
currentValue = new String(ch, start, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException
|
||||
{
|
||||
if (localName.equals("localRepository"))
|
||||
{
|
||||
repositoryLocation = currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getRepositoryLocation()
|
||||
{
|
||||
return repositoryLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDocumentLocator(Locator locator)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endDocument() throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startPrefixMapping(String prefix, String uri) throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endPrefixMapping(String prefix) throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processingInstruction(String target, String data) throws SAXException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skippedEntity(String name) throws SAXException
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,13 +16,12 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.plugins.impl;
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.plugins.MavenService;
|
||||
import org.eclipse.jetty.plugins.model.Plugin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
|
@ -42,9 +41,9 @@ import static org.junit.Assert.assertThat;
|
|||
* <p/>
|
||||
* However this tests should be disabled for the general build and ci.
|
||||
*/
|
||||
public class HttpMavenServiceTest
|
||||
public class HttpMavenServiceIntegrationTest
|
||||
{
|
||||
private MavenService _mavenService = new HttpMavenServiceImpl();
|
||||
private HttpMavenService _mavenService = new HttpMavenService();
|
||||
|
||||
private static final String JETTY_JMX_PLUGIN_NAME = "jetty-jmx";
|
||||
private static final String PRIVATE_NEXUS_REPOSITORY_URL = "http://gravity-design.de:8080/nexus/content/repositories/releases/";
|
||||
|
@ -60,7 +59,7 @@ public class HttpMavenServiceTest
|
|||
@Ignore("requires online repo")
|
||||
public void testListAvailablePlugins()
|
||||
{
|
||||
List<String> pluginNames = _mavenService.listAvailablePlugins();
|
||||
Set<String> pluginNames = _mavenService.listAvailablePlugins();
|
||||
assertThat(pluginNames.size(), is(2));
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// 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
|
||||
//
|
||||
// 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.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
*/
|
||||
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.setVersion("version");
|
||||
_mavenService.setSearchRemoteRepository(false);
|
||||
_mavenService.setSearchLocalRepository(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAvailablePlugins()
|
||||
{
|
||||
Set<String> pluginNames = _mavenService.listAvailablePlugins();
|
||||
assertThat(pluginNames.size(), is(2));
|
||||
assertThat("plugin jetty-plugin found", pluginNames.contains("jetty-plugin"), is(true));
|
||||
assertThat("plugin jetty-anotherplugin found", pluginNames.contains("jetty-anotherplugin"), is(true));
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.plugins.impl;
|
||||
package org.eclipse.jetty.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -24,11 +24,10 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.eclipse.jetty.plugins.MavenService;
|
||||
import org.eclipse.jetty.plugins.model.Plugin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -46,8 +45,8 @@ public class PluginManagerTest
|
|||
{
|
||||
@Mock
|
||||
private MavenService _mavenService;
|
||||
private PluginManagerImpl _pluginManager;
|
||||
private List<String> availablePlugins = createAvailablePluginsTestData();
|
||||
private DefaultPluginManager _Default_pluginManager;
|
||||
private Set<String> availablePlugins = createAvailablePluginsTestData();
|
||||
private ClassLoader _classLoader = this.getClass().getClassLoader();
|
||||
private String _tmpDir;
|
||||
private File _javaTmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
|
@ -57,14 +56,14 @@ public class PluginManagerTest
|
|||
{
|
||||
URL resource = this.getClass().getResource("/jetty_home");
|
||||
_tmpDir = resource.getFile();
|
||||
_pluginManager = new PluginManagerImpl(_mavenService, _tmpDir);
|
||||
_Default_pluginManager = new DefaultPluginManager(_mavenService, _tmpDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAvailablePlugins()
|
||||
{
|
||||
when(_mavenService.listAvailablePlugins()).thenReturn(availablePlugins);
|
||||
List<String> availablePlugins = _pluginManager.listAvailablePlugins();
|
||||
Set<String> availablePlugins = _Default_pluginManager.listAvailablePlugins();
|
||||
assertThat("jetty-jmx not found",
|
||||
availablePlugins.contains("jetty-jmx"), is(true));
|
||||
assertThat("jetty-jta not found",
|
||||
|
@ -74,16 +73,16 @@ public class PluginManagerTest
|
|||
@Test
|
||||
public void testInstallPluginJar()
|
||||
{
|
||||
String pluginName = "jetty-plugin-with-plugin-jar";
|
||||
URL resource = _classLoader.getResource("example-plugin.jar");
|
||||
String pluginName = "jetty-plugin-with-plugin-zip";
|
||||
URL resource = _classLoader.getResource("example-plugin.zip");
|
||||
Assert.assertNotNull(resource);
|
||||
String pluginJar = resource.getFile();
|
||||
File pluginJarFile = new File(pluginJar);
|
||||
Plugin plugin = createTestPlugin(pluginName, pluginJarFile);
|
||||
String pluginZip = resource.getFile();
|
||||
File pluginZipFile = new File(pluginZip);
|
||||
Plugin plugin = createTestPlugin(pluginName, pluginZipFile);
|
||||
|
||||
when(_mavenService.getPlugin(pluginName)).thenReturn(plugin);
|
||||
|
||||
_pluginManager.installPlugin(pluginName);
|
||||
_Default_pluginManager.installPlugin(pluginName);
|
||||
|
||||
File someJar = new File(_tmpDir + File.separator + "lib" + File.separator + "somejar.jar");
|
||||
assertThat("someJar.jar does not exist", someJar.exists(), is(true));
|
||||
|
@ -97,30 +96,30 @@ public class PluginManagerTest
|
|||
public void testInstallPlugins() throws IOException
|
||||
{
|
||||
String pluginName = "jetty-jmx";
|
||||
URL resource = _classLoader.getResource("jetty-jmx-7.6.0.v20120127-plugin.jar");
|
||||
URL resource = _classLoader.getResource("jetty-jmx-version-plugin.zip");
|
||||
Assert.assertNotNull(resource);
|
||||
String jmxPluginConfigJar = resource.getFile();
|
||||
File jmxPluginConfigJarFile = new File(jmxPluginConfigJar);
|
||||
String jmxPluginZip = resource.getFile();
|
||||
File jmxPluginZipFile = new File(jmxPluginZip);
|
||||
|
||||
// Need to copy it to a temp file since the implementation will move the
|
||||
// file and we need to keep the test files where they are.
|
||||
File jmxPluginConfigTempCopy = copyToTempFile(jmxPluginConfigJarFile);
|
||||
File jmxPluginConfigTempCopy = copyToTempFile(jmxPluginZipFile);
|
||||
|
||||
Plugin plugin = new Plugin(pluginName, jmxPluginConfigTempCopy);
|
||||
|
||||
when(_mavenService.getPlugin(pluginName)).thenReturn(plugin);
|
||||
|
||||
_pluginManager.installPlugin(pluginName);
|
||||
_Default_pluginManager.installPlugin(pluginName);
|
||||
|
||||
File metaInf = new File(_tmpDir + File.separator + "META-INF");
|
||||
File jettyXmlConfigFile = new File(_tmpDir + File.separator + "start.d"
|
||||
+ File.separator + "20-jetty-jmx.xml");
|
||||
File jettyJmxJarFile = new File(_tmpDir + File.separator + "lib"
|
||||
+ File.separator + "jetty-jmx-7.6.0.v20120127.jar");
|
||||
+ File.separator + "jetty-jmx-version.jar");
|
||||
assertThat("META-INF should be skipped", metaInf.exists(), not(true));
|
||||
assertThat("20-jetty-jmx.xml does not exist",
|
||||
jettyXmlConfigFile.exists(), is(true));
|
||||
assertThat("jetty-jmx-7.6.0.v20120127.jar does not exist",
|
||||
assertThat("jetty-jmx-version.jar does not exist",
|
||||
jettyJmxJarFile.exists(), is(true));
|
||||
}
|
||||
|
||||
|
@ -135,9 +134,9 @@ public class PluginManagerTest
|
|||
return destFile;
|
||||
}
|
||||
|
||||
private List<String> createAvailablePluginsTestData()
|
||||
private Set<String> createAvailablePluginsTestData()
|
||||
{
|
||||
List<String> availablePlugins = new ArrayList<>();
|
||||
Set<String> availablePlugins = new HashSet<>();
|
||||
availablePlugins.add("jetty-jmx");
|
||||
availablePlugins.add("jetty-jta");
|
||||
return availablePlugins;
|
|
@ -0,0 +1,40 @@
|
|||
//========================================================================
|
||||
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//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
|
||||
//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.
|
||||
//========================================================================
|
||||
package org.eclipse.jetty.plugins.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class MavenUtilsTest
|
||||
{
|
||||
@Test
|
||||
@Ignore("Very environment specific, so disabled in commit. Enable if working on the code.")
|
||||
public void testFindUserSettingsXml()
|
||||
{
|
||||
File settingsXml = MavenUtils.findUserSettingsXml();
|
||||
assertThat("settings.xml is found", settingsXml.exists(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Very environment specific, so disabled in commit. Enable if working on the code.")
|
||||
public void testGetLocalRepositoryLocation()
|
||||
{
|
||||
String repositoryLocation = MavenUtils.getLocalRepositoryLocation();
|
||||
assertThat("maven repository exists", new File(repositoryLocation).exists(), is(true));
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,100 +1,106 @@
|
|||
<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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<name>Jetty :: Utilities</name>
|
||||
<description>Utility classes for Jetty</description>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.util</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>javax.servlet.*;version="2.6.0",org.slf4j;version="[1.5,2.0)";resolution:=optional,org.slf4j.impl;version="[1.5,2.0)";resolution:=optional,*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<name>Jetty :: Utilities</name>
|
||||
<description>Utility classes for Jetty</description>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.util</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>
|
||||
javax.servlet.*;version="2.6.0",org.slf4j;version="[1.5,2.0)";resolution:=optional,org.slf4j.impl;version="[1.5,2.0)";resolution:=optional,*
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!--
|
||||
Required for OSGI
|
||||
-->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>config</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/plugin.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<onlyAnalyze>org.eclipse.jetty.util.*</onlyAnalyze>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!--
|
||||
Required for OSGI
|
||||
This dependency is used to test Slf4jLog.
|
||||
Due to the introduction of src/test/resource/jetty-logging.properties (and the Log.static{} block)
|
||||
the default Log implementation is still StdErrLog during testing.
|
||||
-->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>config</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<onlyAnalyze>org.eclipse.jetty.util.*</onlyAnalyze>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!--
|
||||
This dependency is used to test Slf4jLog.
|
||||
Due to the introduction of src/test/resource/jetty-logging.properties (and the Log.static{} block)
|
||||
the default Log implementation is still StdErrLog during testing.
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
|
||||
<id>plugin</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
|
||||
</assembly>
|
||||
|
Loading…
Reference in New Issue