提交 2236f9a6 编写于 作者: J jurgen

Drivers in maven

上级 335308f6
......@@ -22,6 +22,7 @@
<plugin>
<extension-point id="org.jkiss.dbeaver.pluginService" name="Plugin service" schema="schema/org.jkiss.dbeaver.pluginService.exsd"/>
<extension-point id="org.jkiss.dbeaver.mavenRepository" name="Maven repositories config" schema="schema/org.jkiss.dbeaver.mavenRepository.exsd"/>
<extension-point id="org.jkiss.dbeaver.dataSourceProvider" name="DataSource provider" schema="schema/org.jkiss.dbeaver.dataSourceProvider.exsd"/>
<extension-point id="org.jkiss.dbeaver.databaseEditor" name="Custom Entity Editor" schema="schema/org.jkiss.dbeaver.databaseEditor.exsd"/>
<extension-point id="org.jkiss.dbeaver.dataTypeProvider" name="DataType provider" schema="schema/org.jkiss.dbeaver.dataTypeProvider.exsd"/>
......@@ -2501,4 +2502,8 @@
<service class="org.jkiss.dbeaver.ui.actions.DataSourcePropertyTester$QMService"/>
</extension>
<extension point="org.jkiss.dbeaver.mavenRepository">
<repository name="Central Repository" url="http://central.maven.org/maven2/"/>
</extension>
</plugin>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.mavenRepository" name="Maven Repository"/>
</appInfo>
<documentation>
Plugin Service
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="service" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="service">
<complexType>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.runtime.IPluginService"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -25,6 +25,8 @@ import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDriverFile;
import org.jkiss.dbeaver.model.DBPDriverFileType;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.registry.maven.MavenArtifact;
import org.jkiss.dbeaver.registry.maven.MavenRegistry;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.utils.CommonUtils;
......@@ -140,6 +142,7 @@ public class DriverFileDescriptor implements DBPDriverFile
private File getLocalFile()
{
if (path.startsWith(FILE_SOURCE_MAVEN)) {
MavenArtifact artifact = MavenRegistry.getInstance().findArtifact(path);
return new File(DriverDescriptor.getCustomDriversHome(), getMavenArtifactFileName());
}
// Try to use relative path from installation dir
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.registry.maven;
import org.jkiss.dbeaver.Log;
import org.jkiss.utils.xml.SAXListener;
import org.jkiss.utils.xml.SAXReader;
import org.jkiss.utils.xml.XMLException;
import org.xml.sax.Attributes;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Maven artifact descriptor
*/
public class MavenArtifact
{
static final Log log = Log.getLog(MavenArtifact.class);
private final MavenRepository repository;
private final String groupId;
private final String artifactId;
private List<String> versions = new ArrayList<String>();
private String latestVersion;
private String releaseVersion;
private Date lastUpdate;
public MavenArtifact(MavenRepository repository, String groupId, String artifactId)
throws IOException
{
this.repository = repository;
this.groupId = groupId;
this.artifactId = artifactId;
String metadataPath = getArtifactDir() + "maven-metadata.xml";
URL url = new URL(metadataPath);
URLConnection connection = url.openConnection();
connection.connect();
InputStream mdStream = connection.getInputStream();
try {
SAXReader reader = new SAXReader(mdStream);
reader.parse(new SAXListener() {
public String lastTag;
@Override
public void saxStartElement(SAXReader reader, String namespaceURI, String localName, Attributes atts) throws XMLException {
lastTag = localName;
}
@Override
public void saxText(SAXReader reader, String data) throws XMLException {
if ("version".equals(lastTag)) {
versions.add(data);
} else if ("latest".equals(lastTag)) {
latestVersion = data;
} else if ("release".equals(lastTag)) {
releaseVersion = data;
} else if ("lastUpdate".equals(lastTag)) {
try {
lastUpdate = new Date(Long.parseLong(data));
} catch (NumberFormatException e) {
log.warn(e);
}
}
}
@Override
public void saxEndElement(SAXReader reader, String namespaceURI, String localName) throws XMLException {
lastTag = null;
}
});
} catch (XMLException e) {
log.warn("Error parsing artifact metadata", e);
} finally {
mdStream.close();
}
}
public MavenRepository getRepository() {
return repository;
}
public String getGroupId() {
return groupId;
}
public String getArtifactId() {
return artifactId;
}
public List<String> getVersions() {
return versions;
}
public String getLatestVersion() {
return latestVersion;
}
public String getReleaseVersion() {
return releaseVersion;
}
public Date getLastUpdate() {
return lastUpdate;
}
private String getArtifactDir() {
String dir = (groupId + "/" + artifactId).replace('.', '/');
return repository.getUrl() + dir + "/";
}
public URL getFileURL(String version) throws MalformedURLException {
String fileURL = getArtifactDir() + version + "/" + artifactId + ".jar";
return new URL(fileURL);
}
@Override
public String toString() {
return groupId + ":" + artifactId;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.registry.maven;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.Log;
import java.util.ArrayList;
import java.util.List;
public class MavenRegistry
{
static final Log log = Log.getLog(MavenRegistry.class);
private static MavenRegistry instance = null;
public synchronized static MavenRegistry getInstance()
{
if (instance == null) {
instance = new MavenRegistry();
instance.loadExtensions(Platform.getExtensionRegistry());
}
return instance;
}
private final List<MavenRepository> repositories = new ArrayList<MavenRepository>();
private MavenRegistry()
{
}
public void loadExtensions(IExtensionRegistry registry)
{
// Load data type providers from external plugins
{
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(MavenRepository.EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
MavenRepository repository = new MavenRepository(ext);
repositories.add(repository);
}
}
}
public List<MavenRepository> getRepositories() {
return repositories;
}
public MavenArtifact findArtifact(String mavenUri) {
int divPos = mavenUri.indexOf('/');
if (divPos < 0) {
log.warn("Bad maven uri: " + mavenUri);
return null;
}
mavenUri = mavenUri.substring(divPos + 1);
divPos = mavenUri.indexOf(':');
if (divPos < 0) {
log.warn("Bad maven uri, no group id: " + mavenUri);
return null;
}
String groupId = mavenUri.substring(0, divPos);
int divPos2 = mavenUri.indexOf(':', divPos + 1);
if (divPos2 < 0) {
log.warn("Bad maven uri, no artifact id: " + mavenUri);
return null;
}
String artifactId = mavenUri.substring(divPos + 1, divPos2);
return findArtifact(groupId, artifactId);
}
public MavenArtifact findArtifact(String groupId, String artifactId) {
for (MavenRepository repository : repositories) {
MavenArtifact artifact = repository.getArtifact(groupId, artifactId);
if (artifact != null) {
return artifact;
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.registry.maven;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverActivator;
import org.jkiss.dbeaver.registry.RegistryConstants;
import java.io.File;
import java.io.IOException;
/**
* Maven repository manager.
*/
public class MavenRepository
{
static final Log log = Log.getLog(MavenRepository.class);
public static final String EXTENSION_ID = "org.jkiss.dbeaver.mavenRepository";
private String id;
private String name;
private String url;
public MavenRepository(IConfigurationElement config)
{
this.id = config.getAttribute(RegistryConstants.ATTR_ID);
this.name = config.getAttribute(RegistryConstants.ATTR_NAME);
this.url = config.getAttribute(RegistryConstants.ATTR_URL);
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public MavenArtifact getArtifact(String groupId, String artifactId) {
try {
return new MavenArtifact(this, groupId, artifactId);
} catch (IOException e) {
log.debug(e);
return null;
}
}
public File getCacheLocation()
{
File homeFolder = new File(DBeaverActivator.getInstance().getStateLocation().toFile(), "maven/" + id + "/cache");
if (!homeFolder.exists()) {
if (!homeFolder.mkdirs()) {
log.warn("Can't create maven repository '" + name + "' cache folder '" + homeFolder + "'");
}
}
return homeFolder;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册