Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
b4e55c57
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b4e55c57
编写于
9月 11, 2015
作者:
J
jurgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Maven artifact version info reading (POM)
UR connections refactored.
上级
0bd590e1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
194 addition
and
68 deletion
+194
-68
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DriverFileDescriptor.java
.../src/org/jkiss/dbeaver/registry/DriverFileDescriptor.java
+3
-30
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java
...e/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java
+11
-11
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java
...rg/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java
+123
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenLocalVersion.java
...c/org/jkiss/dbeaver/registry/maven/MavenLocalVersion.java
+9
-3
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/updater/VersionDescriptor.java
...org/jkiss/dbeaver/registry/updater/VersionDescriptor.java
+8
-19
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/RuntimeUtils.java
...aver.core/src/org/jkiss/dbeaver/runtime/RuntimeUtils.java
+38
-3
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/utils/ContentUtils.java
...eaver.model/src/org/jkiss/dbeaver/utils/ContentUtils.java
+2
-2
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DriverFileDescriptor.java
浏览文件 @
b4e55c57
...
...
@@ -38,10 +38,7 @@ import org.jkiss.dbeaver.utils.ContentUtils;
import
org.jkiss.utils.CommonUtils
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.InetSocketAddress
;
import
java.net.Proxy
;
import
java.net.URL
;
import
java.net.*
;
import
java.text.NumberFormat
;
/**
...
...
@@ -203,7 +200,7 @@ public class DriverFileDescriptor implements DBPDriverFile
if
(
artifact
!=
null
)
{
MavenLocalVersion
localVersion
=
artifact
.
getActiveLocalVersion
();
if
(
localVersion
!=
null
)
{
return
localVersion
.
getExternalURL
();
return
localVersion
.
getExternalURL
(
MavenArtifact
.
FILE_JAR
);
}
}
return
null
;
...
...
@@ -319,36 +316,12 @@ public class DriverFileDescriptor implements DBPDriverFile
if
(
isMavenArtifact
())
{
downloadMavenArtifact
(
monitor
);
}
DBPPreferenceStore
prefs
=
DBeaverCore
.
getGlobalPreferenceStore
();
String
proxyHost
=
prefs
.
getString
(
DBeaverPreferences
.
UI_PROXY_HOST
);
Proxy
proxy
=
null
;
if
(!
CommonUtils
.
isEmpty
(
proxyHost
))
{
int
proxyPort
=
prefs
.
getInt
(
DBeaverPreferences
.
UI_PROXY_PORT
);
if
(
proxyPort
<=
0
)
{
log
.
warn
(
"Invalid proxy port: "
+
proxyPort
);
}
proxy
=
new
Proxy
(
Proxy
.
Type
.
HTTP
,
new
InetSocketAddress
(
proxyHost
,
proxyPort
));
}
String
externalURL
=
getExternalURL
();
if
(
externalURL
==
null
)
{
throw
new
IOException
(
"Unresolved file reference: "
+
getPath
());
}
URL
url
=
new
URL
(
externalURL
);
monitor
.
beginTask
(
"Check file "
+
url
.
toString
()
+
"..."
,
1
);
monitor
.
subTask
(
"Connecting to the server"
);
final
HttpURLConnection
connection
=
(
HttpURLConnection
)
(
proxy
==
null
?
url
.
openConnection
()
:
url
.
openConnection
(
proxy
));
connection
.
setReadTimeout
(
10000
);
connection
.
setConnectTimeout
(
10000
);
connection
.
setRequestMethod
(
"GET"
);
//$NON-NLS-1$
connection
.
setInstanceFollowRedirects
(
true
);
connection
.
setRequestProperty
(
"User-Agent"
,
//$NON-NLS-1$
DBeaverCore
.
getProductTitle
());
connection
.
connect
();
if
(
connection
.
getResponseCode
()
!=
200
)
{
throw
new
IOException
(
"Can't find driver file '"
+
url
+
"': "
+
connection
.
getResponseMessage
());
}
final
URLConnection
connection
=
RuntimeUtils
.
openConnection
(
externalURL
);
monitor
.
worked
(
1
);
monitor
.
done
();
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java
浏览文件 @
b4e55c57
...
...
@@ -21,6 +21,7 @@ import org.jkiss.code.NotNull;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.runtime.RuntimeUtils
;
import
org.jkiss.utils.CommonUtils
;
import
org.jkiss.utils.xml.SAXListener
;
import
org.jkiss.utils.xml.SAXReader
;
...
...
@@ -29,8 +30,6 @@ import org.xml.sax.Attributes;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.*
;
import
java.util.regex.Pattern
;
...
...
@@ -40,8 +39,12 @@ import java.util.regex.Pattern;
public
class
MavenArtifact
{
static
final
Log
log
=
Log
.
getLog
(
MavenArtifact
.
class
);
public
static
final
String
MAVEN_METADATA_XML
=
"maven-metadata.xml"
;
public
static
final
String
FILE_JAR
=
"jar"
;
public
static
final
String
FILE_POM
=
"pom"
;
private
final
MavenRepository
repository
;
private
final
String
groupId
;
private
final
String
artifactId
;
...
...
@@ -62,10 +65,7 @@ public class MavenArtifact
public
void
loadMetadata
()
throws
IOException
{
String
metadataPath
=
getArtifactDir
()
+
MAVEN_METADATA_XML
;
URL
url
=
new
URL
(
metadataPath
);
URLConnection
connection
=
url
.
openConnection
();
connection
.
connect
();
InputStream
mdStream
=
connection
.
getInputStream
();
InputStream
mdStream
=
RuntimeUtils
.
openConnectionStream
(
metadataPath
);
try
{
SAXReader
reader
=
new
SAXReader
(
mdStream
);
reader
.
parse
(
new
SAXListener
()
{
...
...
@@ -151,13 +151,13 @@ public class MavenArtifact
return
repository
.
getUrl
()
+
dir
+
"/"
;
}
public
String
getFileURL
(
String
version
)
{
return
getArtifactDir
()
+
version
+
"/"
+
getVersionFileName
(
version
);
public
String
getFileURL
(
String
version
,
String
fileType
)
{
return
getArtifactDir
()
+
version
+
"/"
+
getVersionFileName
(
version
,
fileType
);
}
@NotNull
private
String
getVersionFileName
(
String
version
)
{
return
artifactId
+
"-"
+
version
+
".
jar"
;
private
String
getVersionFileName
(
String
version
,
String
fileType
)
{
return
artifactId
+
"-"
+
version
+
".
"
+
fileType
;
}
@Override
...
...
@@ -190,7 +190,7 @@ public class MavenArtifact
// No version info. Some artifacts do not have older versions in metadata.xml so just warn
log
.
debug
(
"Artifact '"
+
artifactId
+
"' do not have version '"
+
versionStr
+
"' info in metadata"
);
}
version
=
new
MavenLocalVersion
(
this
,
versionStr
,
getVersionFileName
(
versionStr
),
new
Date
());
version
=
new
MavenLocalVersion
(
this
,
versionStr
,
getVersionFileName
(
versionStr
,
FILE_JAR
),
new
Date
());
localVersions
.
add
(
version
);
}
if
(
setActive
)
{
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java
0 → 100644
浏览文件 @
b4e55c57
/*
* 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.dbeaver.runtime.RuntimeUtils
;
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.util.List
;
/**
* Maven artifact version descriptor (POM).
*/
public
class
MavenArtifactVersion
{
static
final
Log
log
=
Log
.
getLog
(
MavenArtifactVersion
.
class
);
private
MavenLocalVersion
localVersion
;
private
String
name
;
private
String
version
;
private
String
description
;
private
String
url
;
private
List
<
String
>
licenses
;
private
List
<
MavenArtifactReference
>
dependencies
;
public
MavenArtifactVersion
(
MavenLocalVersion
localVersion
)
throws
IOException
{
this
.
localVersion
=
localVersion
;
loadPOM
();
}
public
MavenLocalVersion
getLocalVersion
()
{
return
localVersion
;
}
public
String
getName
()
{
return
name
;
}
public
String
getVersion
()
{
return
version
;
}
public
String
getDescription
()
{
return
description
;
}
public
String
getUrl
()
{
return
url
;
}
public
List
<
String
>
getLicenses
()
{
return
licenses
;
}
public
List
<
MavenArtifactReference
>
getDependencies
()
{
return
dependencies
;
}
private
void
loadPOM
()
throws
IOException
{
String
pomURL
=
localVersion
.
getArtifact
().
getFileURL
(
localVersion
.
getVersion
(),
MavenArtifact
.
FILE_POM
);
InputStream
mdStream
=
RuntimeUtils
.
openConnectionStream
(
pomURL
);
try
{
SAXReader
reader
=
new
SAXReader
(
mdStream
);
reader
.
parse
(
new
SAXListener
()
{
private
boolean
inRoot
=
true
;
private
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
(
inRoot
)
{
if
(
"name"
.
equals
(
lastTag
))
{
name
=
data
;
}
else
if
(
"version"
.
equals
(
lastTag
))
{
version
=
data
;
}
else
if
(
"description"
.
equals
(
lastTag
))
{
description
=
data
;
}
else
if
(
"url"
.
equals
(
lastTag
))
{
url
=
data
;
}
}
}
@Override
public
void
saxEndElement
(
SAXReader
reader
,
String
namespaceURI
,
String
localName
)
throws
XMLException
{
lastTag
=
null
;
}
});
}
catch
(
XMLException
e
)
{
log
.
warn
(
"Error parsing POM"
,
e
);
}
finally
{
mdStream
.
close
();
}
}
@Override
public
String
toString
()
{
return
localVersion
.
toString
();
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenLocalVersion.java
浏览文件 @
b4e55c57
...
...
@@ -21,7 +21,9 @@ import java.io.File;
import
java.util.Date
;
/**
* Maven artifact descriptor
* Maven artifact version info.
* It is a resolved version information. This version exists in maven repository and can be obtained.
* Also it is cached locally.
*/
public
class
MavenLocalVersion
{
...
...
@@ -37,6 +39,10 @@ public class MavenLocalVersion
this
.
updateTime
=
updateTime
;
}
public
MavenArtifact
getArtifact
()
{
return
artifact
;
}
public
String
getVersion
()
{
return
version
;
}
...
...
@@ -58,7 +64,7 @@ public class MavenLocalVersion
return
new
File
(
artifact
.
getRepository
().
getLocalCacheDir
(),
artifact
.
getGroupId
()
+
"/"
+
fileName
);
}
public
String
getExternalURL
()
{
return
artifact
.
getFileURL
(
version
);
public
String
getExternalURL
(
String
fileType
)
{
return
artifact
.
getFileURL
(
version
,
fileType
);
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/updater/VersionDescriptor.java
浏览文件 @
b4e55c57
...
...
@@ -18,6 +18,7 @@
package
org.jkiss.dbeaver.registry.updater
;
import
org.jkiss.dbeaver.runtime.RuntimeUtils
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
import
org.jkiss.utils.CommonUtils
;
import
org.jkiss.utils.xml.XMLException
;
...
...
@@ -28,8 +29,6 @@ import org.w3c.dom.Element;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -53,26 +52,16 @@ public class VersionDescriptor {
public
VersionDescriptor
(
String
fileAddr
)
throws
IOException
{
URL
url
=
new
URL
(
fileAddr
);
URLConnection
connection
=
url
.
openConnection
();
try
{
connection
.
setConnectTimeout
(
10000
);
connection
.
setReadTimeout
(
10000
);
connection
.
connect
();
InputStream
inputStream
=
RuntimeUtils
.
openConnectionStream
(
fileAddr
);
try
{
InputStream
inputStream
=
connection
.
getInputStream
();
try
{
Document
document
=
XMLUtils
.
parseDocument
(
inputStream
);
parseVersionInfo
(
document
);
}
finally
{
ContentUtils
.
close
(
inputStream
);
}
}
catch
(
XMLException
e
)
{
throw
new
IOException
(
"XML parse error"
,
e
);
Document
document
=
XMLUtils
.
parseDocument
(
inputStream
);
parseVersionInfo
(
document
);
}
finally
{
ContentUtils
.
close
(
inputStream
);
}
}
finally
{
// nothing
}
catch
(
XMLException
e
)
{
throw
new
IOException
(
"XML parse error"
,
e
);
}
}
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/RuntimeUtils.java
浏览文件 @
b4e55c57
...
...
@@ -22,9 +22,11 @@ import org.eclipse.core.runtime.jobs.Job;
import
org.eclipse.jface.operation.IRunnableContext
;
import
org.eclipse.jface.operation.IRunnableWithProgress
;
import
org.eclipse.swt.program.Program
;
import
org.jkiss.dbeaver.DBeaverPreferences
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.core.CoreMessages
;
import
org.jkiss.dbeaver.core.DBeaverCore
;
import
org.jkiss.dbeaver.model.DBPPreferenceStore
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress
;
import
org.jkiss.dbeaver.runtime.load.ILoadService
;
...
...
@@ -32,13 +34,13 @@ import org.jkiss.dbeaver.runtime.load.ILoadVisualizer;
import
org.jkiss.dbeaver.runtime.load.jobs.LoadingJob
;
import
org.jkiss.dbeaver.utils.GeneralUtils
;
import
org.jkiss.utils.ArrayUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.InvocationTargetException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.net.*
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
...
...
@@ -260,4 +262,37 @@ public class RuntimeUtils {
}
}
public
static
InputStream
openConnectionStream
(
String
urlString
)
throws
IOException
{
URLConnection
connection
=
openConnection
(
urlString
);
return
connection
.
getInputStream
();
}
public
static
URLConnection
openConnection
(
String
urlString
)
throws
IOException
{
DBPPreferenceStore
prefs
=
DBeaverCore
.
getGlobalPreferenceStore
();
String
proxyHost
=
prefs
.
getString
(
DBeaverPreferences
.
UI_PROXY_HOST
);
Proxy
proxy
=
null
;
if
(!
CommonUtils
.
isEmpty
(
proxyHost
))
{
int
proxyPort
=
prefs
.
getInt
(
DBeaverPreferences
.
UI_PROXY_PORT
);
if
(
proxyPort
<=
0
)
{
log
.
warn
(
"Invalid proxy port: "
+
proxyPort
);
}
proxy
=
new
Proxy
(
Proxy
.
Type
.
HTTP
,
new
InetSocketAddress
(
proxyHost
,
proxyPort
));
}
URL
url
=
new
URL
(
urlString
);
final
HttpURLConnection
connection
=
(
HttpURLConnection
)
(
proxy
==
null
?
url
.
openConnection
()
:
url
.
openConnection
(
proxy
));
connection
.
setReadTimeout
(
10000
);
connection
.
setConnectTimeout
(
10000
);
connection
.
setRequestMethod
(
"GET"
);
//$NON-NLS-1$
connection
.
setInstanceFollowRedirects
(
true
);
connection
.
setRequestProperty
(
"User-Agent"
,
//$NON-NLS-1$
DBeaverCore
.
getProductTitle
());
connection
.
connect
();
if
(
connection
.
getResponseCode
()
!=
200
)
{
throw
new
IOException
(
"File not found '"
+
urlString
+
"': "
+
connection
.
getResponseMessage
());
}
return
connection
;
}
}
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/utils/ContentUtils.java
浏览文件 @
b4e55c57
...
...
@@ -22,11 +22,11 @@ import org.eclipse.core.resources.*;
import
org.eclipse.core.runtime.CoreException
;
import
org.eclipse.core.runtime.IPath
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.ModelPreferences
;
import
org.jkiss.dbeaver.model.messages.ModelMessages
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.ModelPreferences
;
import
org.jkiss.dbeaver.model.DBPApplication
;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.messages.ModelMessages
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.utils.ArrayUtils
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录