Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
40c76a65
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,发现更多精彩内容 >>
提交
40c76a65
编写于
10月 08, 2015
作者:
J
jurgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Maven cache save
Former-commit-id:
b2401277
上级
d20914a1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
91 addition
and
47 deletion
+91
-47
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java
...e/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java
+2
-2
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java
...rg/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java
+5
-9
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenLocalVersion.java
...c/org/jkiss/dbeaver/registry/maven/MavenLocalVersion.java
+6
-2
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java
...e/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java
+26
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRepository.java
...src/org/jkiss/dbeaver/registry/maven/MavenRepository.java
+52
-34
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifact.java
浏览文件 @
40c76a65
...
...
@@ -165,7 +165,7 @@ public class MavenArtifact
}
@NotNull
private
String
getVersionFileName
(
String
version
,
String
fileType
)
{
String
getVersionFileName
(
String
version
,
String
fileType
)
{
return
artifactId
+
"-"
+
version
+
"."
+
fileType
;
}
...
...
@@ -199,7 +199,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
,
FILE_JAR
),
new
Date
());
version
=
new
MavenLocalVersion
(
this
,
versionStr
,
new
Date
());
version
.
getMetaData
(
monitor
);
localVersions
.
add
(
version
);
}
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenArtifactVersion.java
浏览文件 @
40c76a65
...
...
@@ -130,20 +130,15 @@ public class MavenArtifactVersion {
return
this
.
dependencies
;
}
List
<
MavenArtifactDependency
>
getDependencies
()
{
return
dependencies
;
}
@Override
public
String
toString
()
{
return
localVersion
.
toString
();
}
private
enum
ParserState
{
ROOT
,
PARENT
,
PROPERTIES
,
LICENSE
,
DEPENDENCIES
,
DEPENDENCY
}
private
void
loadPOM
(
DBRProgressMonitor
monitor
)
throws
IOException
{
String
pomURL
=
localVersion
.
getArtifact
().
getFileURL
(
localVersion
.
getVersion
(),
MavenArtifact
.
FILE_POM
);
monitor
.
subTask
(
"Load POM "
+
localVersion
);
...
...
@@ -272,4 +267,5 @@ public class MavenArtifactVersion {
private
String
evaluateString
(
String
value
)
{
return
GeneralUtils
.
replaceVariables
(
value
,
variableResolver
);
}
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenLocalVersion.java
浏览文件 @
40c76a65
...
...
@@ -41,10 +41,10 @@ public class MavenLocalVersion
private
Date
updateTime
;
private
MavenArtifactVersion
metaData
;
public
MavenLocalVersion
(
MavenArtifact
artifact
,
String
version
,
String
fileName
,
Date
updateTime
)
{
public
MavenLocalVersion
(
MavenArtifact
artifact
,
String
version
,
Date
updateTime
)
{
this
.
artifact
=
artifact
;
this
.
version
=
version
;
this
.
fileName
=
fileName
;
this
.
fileName
=
artifact
.
getVersionFileName
(
version
,
MavenArtifact
.
FILE_JAR
)
;
this
.
updateTime
=
updateTime
;
}
...
...
@@ -94,6 +94,10 @@ public class MavenLocalVersion
return
metaData
;
}
MavenArtifactVersion
getMetaData
()
{
return
metaData
;
}
@Override
public
String
toString
()
{
return
artifact
.
toString
()
+
":"
+
version
;
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRegistry.java
浏览文件 @
40c76a65
...
...
@@ -18,11 +18,15 @@
package
org.jkiss.dbeaver.registry.maven
;
import
org.eclipse.core.runtime.IConfigurationElement
;
import
org.eclipse.core.runtime.IStatus
;
import
org.eclipse.core.runtime.Platform
;
import
org.eclipse.core.runtime.Status
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBeaverPreferences
;
import
org.jkiss.dbeaver.core.DBeaverCore
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.runtime.AbstractJob
;
import
org.jkiss.utils.CommonUtils
;
import
java.io.IOException
;
...
...
@@ -72,6 +76,9 @@ public class MavenRegistry
MAVEN_LOCAL_REPO_NAME
,
localRepoURL
,
true
);
// Start config saver
new
ConfigSaver
().
schedule
(
ConfigSaver
.
SAVE_PERIOD
);
}
public
void
loadCustomRepositories
()
{
...
...
@@ -188,4 +195,23 @@ public class MavenRegistry
return
null
;
}
private
class
ConfigSaver
extends
AbstractJob
{
public
static
final
int
SAVE_PERIOD
=
1000
;
protected
ConfigSaver
()
{
super
(
"Maven local cache persister"
);
}
@Override
protected
IStatus
run
(
DBRProgressMonitor
monitor
)
{
for
(
MavenRepository
repository
:
repositories
)
{
repository
.
saveCacheIfNeeded
();
}
schedule
(
SAVE_PERIOD
);
return
Status
.
OK_STATUS
;
}
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/maven/MavenRepository.java
浏览文件 @
40c76a65
...
...
@@ -33,10 +33,7 @@ import org.jkiss.utils.xml.XMLException;
import
org.xml.sax.Attributes
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.*
;
/**
* Maven repository manager.
...
...
@@ -52,6 +49,7 @@ public class MavenRepository
private
static
final
String
TAG_CACHE
=
"cache"
;
private
static
final
String
TAG_ARTIFACT
=
"artifact"
;
private
static
final
String
TAG_VERSION
=
"version"
;
private
static
final
String
TAG_DEPENDENCY
=
"dependency"
;
public
static
final
String
ATTR_NAME
=
"name"
;
public
static
final
String
ATTR_URL
=
"url"
;
...
...
@@ -59,7 +57,9 @@ public class MavenRepository
public
static
final
String
ATTR_ARTIFACT_ID
=
"artifactId"
;
public
static
final
String
ATTR_ACTIVE_VERSION
=
"activeVersion"
;
public
static
final
String
ATTR_VERSION
=
"version"
;
public
static
final
String
ATTR_FILE
=
"file"
;
public
static
final
String
ATTR_PATH
=
"path"
;
public
static
final
String
ATTR_SCOPE
=
"scope"
;
private
static
final
String
ATTR_PARENT
=
"parent"
;
public
static
final
String
ATTR_UPDATE_TIME
=
"updateTime"
;
private
String
id
;
...
...
@@ -70,7 +70,7 @@ public class MavenRepository
private
transient
volatile
boolean
needsToSave
=
false
;
private
List
<
MavenArtifact
>
cachedArtifacts
=
new
ArrayList
<
MavenArtifact
>();
private
List
<
MavenArtifact
>
cachedArtifacts
=
new
ArrayList
<>();
public
MavenRepository
(
IConfigurationElement
config
)
{
...
...
@@ -116,7 +116,7 @@ public class MavenRepository
}
@Nullable
public
MavenArtifact
findArtifact
(
@NotNull
String
groupId
,
@NotNull
String
artifactId
,
boolean
resolve
)
{
public
synchronized
MavenArtifact
findArtifact
(
@NotNull
String
groupId
,
@NotNull
String
artifactId
,
boolean
resolve
)
{
for
(
MavenArtifact
artifact
:
cachedArtifacts
)
{
if
(
artifact
.
getGroupId
().
equals
(
groupId
)
&&
artifact
.
getArtifactId
().
equals
(
artifactId
))
{
return
artifact
;
...
...
@@ -137,7 +137,7 @@ public class MavenRepository
return
null
;
}
void
resetArtifactCache
(
@NotNull
String
groupId
,
@NotNull
String
artifactId
)
{
synchronized
void
resetArtifactCache
(
@NotNull
String
groupId
,
@NotNull
String
artifactId
)
{
for
(
Iterator
<
MavenArtifact
>
iterator
=
cachedArtifacts
.
iterator
();
iterator
.
hasNext
();
)
{
MavenArtifact
artifact
=
iterator
.
next
();
if
(
artifact
.
getGroupId
().
equals
(
groupId
)
&&
artifact
.
getArtifactId
().
equals
(
artifactId
))
{
...
...
@@ -146,11 +146,6 @@ public class MavenRepository
}
}
private
synchronized
void
addCachedArtifact
(
@NotNull
MavenArtifact
artifact
)
{
cachedArtifacts
.
add
(
artifact
);
// saveCache();
}
File
getLocalCacheDir
()
{
File
homeFolder
=
new
File
(
DBeaverActivator
.
getInstance
().
getStateLocation
().
toFile
(),
"maven/"
+
id
+
"/"
);
...
...
@@ -187,7 +182,6 @@ public class MavenRepository
MavenLocalVersion
version
=
new
MavenLocalVersion
(
lastArtifact
,
atts
.
getValue
(
ATTR_VERSION
),
atts
.
getValue
(
ATTR_FILE
),
new
Date
(
Long
.
parseLong
(
atts
.
getValue
(
ATTR_UPDATE_TIME
))));
lastArtifact
.
addLocalVersion
(
version
);
}
...
...
@@ -213,6 +207,13 @@ public class MavenRepository
}
}
void
saveCacheIfNeeded
()
{
if
(
needsToSave
)
{
saveCache
();
needsToSave
=
false
;
}
}
synchronized
private
void
saveCache
()
{
try
{
File
cacheDir
=
getLocalCacheDir
();
...
...
@@ -226,30 +227,47 @@ public class MavenRepository
try
{
XMLBuilder
xml
=
new
XMLBuilder
(
out
,
"utf-8"
);
xml
.
setButify
(
true
);
xml
.
startElement
(
TAG_CACHE
);
xml
.
addAttribute
(
ATTR_NAME
,
name
);
xml
.
addAttribute
(
ATTR_URL
,
url
);
try
(
XMLBuilder
.
Element
e
=
xml
.
startElement
(
TAG_CACHE
))
{
xml
.
addAttribute
(
ATTR_NAME
,
name
);
xml
.
addAttribute
(
ATTR_URL
,
url
);
for
(
MavenArtifact
artifact
:
cachedArtifacts
)
{
if
(
CommonUtils
.
isEmpty
(
artifact
.
getLocalVersions
()))
{
continue
;
}
xml
.
startElement
(
TAG_ARTIFACT
);
xml
.
addAttribute
(
ATTR_GROUP_ID
,
artifact
.
getGroupId
());
xml
.
addAttribute
(
ATTR_ARTIFACT_ID
,
artifact
.
getArtifactId
());
xml
.
addAttribute
(
ATTR_ACTIVE_VERSION
,
artifact
.
getActiveVersion
());
for
(
MavenLocalVersion
version
:
artifact
.
getLocalVersions
())
{
xml
.
startElement
(
TAG_VERSION
);
xml
.
addAttribute
(
ATTR_VERSION
,
version
.
getVersion
());
xml
.
addAttribute
(
ATTR_FILE
,
version
.
getFileName
());
xml
.
addAttribute
(
ATTR_UPDATE_TIME
,
version
.
getUpdateTime
().
getTime
());
xml
.
endElement
();
for
(
MavenArtifact
artifact
:
cachedArtifacts
)
{
if
(
CommonUtils
.
isEmpty
(
artifact
.
getLocalVersions
()))
{
continue
;
}
try
(
XMLBuilder
.
Element
e1
=
xml
.
startElement
(
TAG_ARTIFACT
))
{
xml
.
addAttribute
(
ATTR_GROUP_ID
,
artifact
.
getGroupId
());
xml
.
addAttribute
(
ATTR_ARTIFACT_ID
,
artifact
.
getArtifactId
());
xml
.
addAttribute
(
ATTR_ACTIVE_VERSION
,
artifact
.
getActiveVersion
());
for
(
MavenLocalVersion
version
:
artifact
.
getLocalVersions
())
{
try
(
XMLBuilder
.
Element
e2
=
xml
.
startElement
(
TAG_VERSION
))
{
xml
.
addAttribute
(
ATTR_VERSION
,
version
.
getVersion
());
xml
.
addAttribute
(
ATTR_UPDATE_TIME
,
version
.
getUpdateTime
().
getTime
());
MavenArtifactVersion
metaData
=
version
.
getMetaData
();
if
(
metaData
!=
null
)
{
MavenArtifactReference
parentReference
=
metaData
.
getParentReference
();
if
(
parentReference
!=
null
)
{
xml
.
addAttribute
(
ATTR_PARENT
,
parentReference
.
getPath
());
}
List
<
MavenArtifactDependency
>
dependencies
=
metaData
.
getDependencies
();
if
(
dependencies
!=
null
)
{
for
(
MavenArtifactDependency
dependency
:
dependencies
)
{
try
(
XMLBuilder
.
Element
e3
=
xml
.
startElement
(
TAG_DEPENDENCY
))
{
xml
.
addAttribute
(
ATTR_PATH
,
dependency
.
getPath
());
if
(
dependency
.
getScope
()
!=
MavenArtifactDependency
.
Scope
.
COMPILE
)
{
xml
.
addAttribute
(
ATTR_SCOPE
,
dependency
.
getScope
().
name
().
toLowerCase
(
Locale
.
ENGLISH
));
}
}
}
}
}
}
}
}
}
xml
.
endElement
();
}
xml
.
endElement
();
xml
.
flush
();
}
finally
{
IOUtils
.
close
(
out
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录