Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f67479df
提交
f67479df
authored
10月 26, 2015
作者:
Ivo Smid
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ISSUE-132 - SourceCompiler throws syntax error on javac warning
上级
79ea94ee
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
165 行增加
和
4 行删除
+165
-4
SourceCompiler.java
h2/src/main/org/h2/util/SourceCompiler.java
+18
-3
javax.annotation.processing.Processor
...t/META-INF/services/javax.annotation.processing.Processor
+1
-0
TestAnnotationProcessor.java
h2/src/test/org/h2/test/ap/TestAnnotationProcessor.java
+65
-0
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+81
-1
没有找到文件。
h2/src/main/org/h2/util/SourceCompiler.java
浏览文件 @
f67479df
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataInputStream
;
import
java.io.File
;
import
java.io.File
;
...
@@ -13,6 +14,7 @@ import java.io.IOException;
...
@@ -13,6 +14,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.io.Writer
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.Array
;
...
@@ -361,9 +363,22 @@ public class SourceCompiler {
...
@@ -361,9 +363,22 @@ public class SourceCompiler {
}
}
private
static
void
handleSyntaxError
(
String
output
)
{
private
static
void
handleSyntaxError
(
String
output
)
{
if
(
output
.
startsWith
(
"Note:"
)
||
output
.
startsWith
(
"warning:"
))
{
boolean
syntaxError
=
false
;
final
BufferedReader
reader
=
new
BufferedReader
(
new
StringReader
(
output
));
try
{
for
(
String
line
;
(
line
=
reader
.
readLine
())
!=
null
;
)
{
if
(
line
.
startsWith
(
"Note:"
)
||
line
.
startsWith
(
"warning:"
))
{
// just a warning (e.g. unchecked or unsafe operations)
// just a warning (e.g. unchecked or unsafe operations)
}
else
if
(
output
.
length
()
>
0
)
{
}
else
{
syntaxError
=
true
;
break
;
}
}
}
catch
(
IOException
ignored
)
{
// exception ignored
}
if
(
syntaxError
)
{
output
=
StringUtils
.
replaceAll
(
output
,
COMPILE_DIR
,
""
);
output
=
StringUtils
.
replaceAll
(
output
,
COMPILE_DIR
,
""
);
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
output
);
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
output
);
}
}
...
...
h2/src/test/META-INF/services/javax.annotation.processing.Processor
0 → 100644
浏览文件 @
f67479df
org.h2.test.ap.TestAnnotationProcessor
\ No newline at end of file
h2/src/test/org/h2/test/ap/TestAnnotationProcessor.java
0 → 100644
浏览文件 @
f67479df
package
org
.
h2
.
test
.
ap
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
import
javax.annotation.processing.AbstractProcessor
;
import
javax.annotation.processing.RoundEnvironment
;
import
javax.lang.model.SourceVersion
;
import
javax.lang.model.element.TypeElement
;
import
javax.tools.Diagnostic
;
public
class
TestAnnotationProcessor
extends
AbstractProcessor
{
public
static
final
String
MESSAGES_KEY
=
TestAnnotationProcessor
.
class
.
getName
()
+
"-messages"
;
public
Set
<
String
>
getSupportedAnnotationTypes
()
{
for
(
OutputMessage
outputMessage
:
findMessages
())
{
processingEnv
.
getMessager
().
printMessage
(
outputMessage
.
kind
,
outputMessage
.
message
);
}
return
Collections
.
emptySet
();
}
private
List
<
OutputMessage
>
findMessages
()
{
final
String
messagesStr
=
System
.
getProperty
(
MESSAGES_KEY
);
if
(
messagesStr
==
null
||
messagesStr
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
else
{
final
List
<
OutputMessage
>
outputMessages
=
new
ArrayList
<
OutputMessage
>();
for
(
String
msg
:
messagesStr
.
split
(
"\\|"
))
{
final
String
[]
split
=
msg
.
split
(
","
);
if
(
split
.
length
==
2
)
{
outputMessages
.
add
(
new
OutputMessage
(
Diagnostic
.
Kind
.
valueOf
(
split
[
0
]),
split
[
1
]));
}
else
{
throw
new
IllegalStateException
(
"Unable to parse messages definition for: '"
+
messagesStr
+
"'"
);
}
}
return
outputMessages
;
}
}
public
SourceVersion
getSupportedSourceVersion
()
{
return
SourceVersion
.
RELEASE_6
;
}
@Override
public
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
return
false
;
}
private
static
class
OutputMessage
{
public
final
Diagnostic
.
Kind
kind
;
public
final
String
message
;
private
OutputMessage
(
Diagnostic
.
Kind
kind
,
String
message
)
{
this
.
kind
=
kind
;
this
.
message
=
message
;
}
}
}
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
f67479df
...
@@ -41,8 +41,10 @@ import org.h2.api.Aggregate;
...
@@ -41,8 +41,10 @@ import org.h2.api.Aggregate;
import
org.h2.api.AggregateFunction
;
import
org.h2.api.AggregateFunction
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.test.ap.TestAnnotationProcessor
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.New
;
import
org.h2.util.New
;
...
@@ -103,6 +105,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -103,6 +105,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testTranslate
();
testTranslate
();
testGenerateSeries
();
testGenerateSeries
();
testFileWrite
();
testFileWrite
();
testAnnotationProcessorsOutput
();
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
}
}
...
@@ -1163,7 +1166,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1163,7 +1166,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
call
.
execute
();
call
.
execute
();
assertEquals
(
Integer
[].
class
.
getName
(),
call
.
getArray
(
1
).
getArray
()
assertEquals
(
Integer
[].
class
.
getName
(),
call
.
getArray
(
1
).
getArray
()
.
getClass
().
getName
());
.
getClass
().
getName
());
assertEquals
(
new
Integer
[]
{
2
,
1
},
(
Integer
[])
call
.
getObject
(
1
));
assertEquals
(
new
Integer
[]
{
2
,
1
},
(
Integer
[])
call
.
getObject
(
1
));
stat
.
execute
(
"drop alias array_test"
);
stat
.
execute
(
"drop alias array_test"
);
...
@@ -1778,6 +1781,83 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1778,6 +1781,83 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
conn
.
close
();
}
}
private
void
testAnnotationProcessorsOutput
()
throws
SQLException
{
testAnnotationProcessorsOutput_emptyKey
();
testAnnotationProcessorsOutput_invalidKey
();
testAnnotationProcessorsOutput_oneInvalidKey
();
testAnnotationProcessorsOutput_warnAndError
();
}
private
void
testAnnotationProcessorsOutput_emptyKey
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
""
);
callCompiledFunction
(
"test_atp_empty_key"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
testAnnotationProcessorsOutput_invalidKey
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
"invalid"
);
callCompiledFunction
(
"test_atp_invalid_key"
);
fail
();
}
catch
(
JdbcSQLException
e
)
{
assertEquals
(
ErrorCode
.
SYNTAX_ERROR_1
,
e
.
getErrorCode
());
assertContains
(
e
.
getMessage
(),
"'invalid'"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
testAnnotationProcessorsOutput_oneInvalidKey
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
"invalid,foo"
);
callCompiledFunction
(
"test_atp_one_invalid_key"
);
fail
();
}
catch
(
JdbcSQLException
e
)
{
assertEquals
(
ErrorCode
.
SYNTAX_ERROR_1
,
e
.
getErrorCode
());
assertContains
(
e
.
getMessage
(),
"enum"
);
assertContains
(
e
.
getMessage
(),
"Kind.invalid"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
testAnnotationProcessorsOutput_warnAndError
()
throws
SQLException
{
try
{
System
.
setProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
,
"WARNING,foo1|ERROR,foo2"
);
callCompiledFunction
(
"test_atp_warn_and_error"
);
fail
();
}
catch
(
JdbcSQLException
e
)
{
assertEquals
(
ErrorCode
.
SYNTAX_ERROR_1
,
e
.
getErrorCode
());
assertContains
(
e
.
getMessage
(),
"foo1"
);
assertContains
(
e
.
getMessage
(),
"foo2"
);
}
finally
{
System
.
clearProperty
(
TestAnnotationProcessor
.
MESSAGES_KEY
);
}
}
private
void
callCompiledFunction
(
String
functionName
)
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
stat
.
execute
(
"create alias "
+
functionName
+
" AS "
+
"$$ boolean "
+
functionName
+
"() "
+
"{ return true; } $$;"
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select "
+
functionName
+
"() from dual"
);
rs
=
stmt
.
executeQuery
();
rs
.
next
();
assertEquals
(
Boolean
.
class
.
getName
(),
rs
.
getObject
(
1
).
getClass
().
getName
());
stat
.
execute
(
"drop alias "
+
functionName
+
""
);
conn
.
close
();
}
private
void
assertCallResult
(
String
expected
,
Statement
stat
,
String
sql
)
private
void
assertCallResult
(
String
expected
,
Statement
stat
,
String
sql
)
throws
SQLException
{
throws
SQLException
{
ResultSet
rs
=
stat
.
executeQuery
(
"CALL "
+
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
"CALL "
+
sql
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论