Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
3f289a1f
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3f289a1f
编写于
8月 24, 2010
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
Reviewed-by: darcy
上级
6c04f8fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
182 addition
and
4 deletion
+182
-4
langtools/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java
...re/classes/com/sun/tools/javac/processing/JavacFiler.java
+10
-4
langtools/test/tools/javac/processing/filer/TestGetResource2.java
...s/test/tools/javac/processing/filer/TestGetResource2.java
+172
-0
未找到文件。
langtools/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java
浏览文件 @
3f289a1f
...
...
@@ -34,6 +34,7 @@ import javax.lang.model.element.Element;
import
java.util.*
;
import
java.io.Closeable
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.FilterOutputStream
;
...
...
@@ -450,10 +451,15 @@ public class JavacFiler implements Filer, Closeable {
// TODO: Only support reading resources in selected output
// locations? Only allow reading of non-source, non-class
// files from the supported input locations?
FileObject
fileObject
=
fileManager
.
getFileForOutput
(
location
,
pkg
.
toString
(),
relativeName
.
toString
(),
null
);
FileObject
fileObject
=
fileManager
.
getFileForInput
(
location
,
pkg
.
toString
(),
relativeName
.
toString
());
if
(
fileObject
==
null
)
{
String
name
=
(
pkg
.
length
()
==
0
)
?
relativeName
.
toString
()
:
(
pkg
+
"/"
+
relativeName
);
throw
new
FileNotFoundException
(
name
);
}
// If the path was already opened for writing, throw an exception.
checkFileReopening
(
fileObject
,
false
);
return
new
FilerInputFileObject
(
fileObject
);
...
...
langtools/test/tools/javac/processing/filer/TestGetResource2.java
0 → 100644
浏览文件 @
3f289a1f
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6929404
* @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
*/
import
java.io.*
;
import
java.security.*
;
import
java.util.*
;
import
javax.annotation.processing.*
;
import
javax.lang.model.*
;
import
javax.lang.model.element.*
;
import
javax.tools.*
;
import
javax.tools.Diagnostic.Kind
;
import
javax.tools.JavaCompiler.CompilationTask
;
public
class
TestGetResource2
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestGetResource2
().
run
();
}
void
run
()
throws
Exception
{
JavaCompiler
javac
=
ToolProvider
.
getSystemJavaCompiler
();
CodeSource
cs
=
javac
.
getClass
().
getProtectionDomain
().
getCodeSource
();
if
(
cs
==
null
)
{
System
.
err
.
println
(
"got compiler from "
+
ClassLoader
.
getSystemResource
(
javac
.
getClass
().
getName
().
replace
(
"."
,
"/"
)+
".class"
));
}
else
{
System
.
err
.
println
(
"got compiler from "
+
cs
.
getLocation
());
}
testSingleSourceDir
(
javac
);
testCompositeSourcePath
(
javac
);
testMissingResource
(
javac
);
}
private
void
testSingleSourceDir
(
JavaCompiler
javac
)
throws
Exception
{
System
.
err
.
println
(
"testSingleSourceDir"
);
File
tmpdir
=
new
File
(
"testSingleSourceDir"
);
File
srcdir
=
new
File
(
tmpdir
,
"src"
);
File
destdir
=
new
File
(
tmpdir
,
"dest"
);
write
(
srcdir
,
"pkg/X.java"
,
"package pkg; class X {}"
);
write
(
srcdir
,
"resources/file.txt"
,
"hello"
);
destdir
.
mkdirs
();
CompilationTask
task
=
javac
.
getTask
(
null
,
null
,
null
,
Arrays
.
asList
(
"-sourcepath"
,
srcdir
.
toString
(),
"-d"
,
destdir
.
toString
()),
Collections
.
singleton
(
"pkg.X"
),
null
);
task
.
setProcessors
(
Collections
.
singleton
(
new
AnnoProc
()));
boolean
result
=
task
.
call
();
System
.
err
.
println
(
"javac result with single source dir: "
+
result
);
expect
(
result
,
true
);
}
private
void
testCompositeSourcePath
(
JavaCompiler
javac
)
throws
Exception
{
System
.
err
.
println
(
"testCompositeSearchPath"
);
File
tmpdir
=
new
File
(
"testCompositeSourcePath"
);
File
srcdir
=
new
File
(
tmpdir
,
"src"
);
File
rsrcdir
=
new
File
(
tmpdir
,
"rsrc"
);
File
destdir
=
new
File
(
tmpdir
,
"dest"
);
write
(
srcdir
,
"pkg/X.java"
,
"package pkg; class X {}"
);
write
(
rsrcdir
,
"resources/file.txt"
,
"hello"
);
destdir
.
mkdirs
();
CompilationTask
task
=
javac
.
getTask
(
null
,
null
,
null
,
Arrays
.
asList
(
"-sourcepath"
,
srcdir
+
File
.
pathSeparator
+
rsrcdir
,
"-d"
,
destdir
.
toString
()),
Collections
.
singleton
(
"pkg.X"
),
null
);
task
.
setProcessors
(
Collections
.
singleton
(
new
AnnoProc
()));
boolean
result
=
task
.
call
();
System
.
err
.
println
(
"javac result with composite source path: "
+
result
);
expect
(
result
,
true
);
}
private
void
testMissingResource
(
JavaCompiler
javac
)
throws
Exception
{
System
.
err
.
println
(
"testMissingResource"
);
File
tmpdir
=
new
File
(
"testMissingResource"
);
File
srcdir
=
new
File
(
tmpdir
,
"src"
);
File
destdir
=
new
File
(
tmpdir
,
"dest"
);
write
(
srcdir
,
"pkg/X.java"
,
"package pkg; class X {}"
);
destdir
.
mkdirs
();
CompilationTask
task
=
javac
.
getTask
(
null
,
null
,
null
,
Arrays
.
asList
(
"-sourcepath"
,
srcdir
.
toString
(),
"-d"
,
destdir
.
toString
()),
Collections
.
singleton
(
"pkg.X"
),
null
);
task
.
setProcessors
(
Collections
.
singleton
(
new
AnnoProc
()));
boolean
result
=
task
.
call
();
System
.
err
.
println
(
"javac result when missing resource: "
+
result
);
expect
(
result
,
false
);
if
(
errors
>
0
)
throw
new
Exception
(
errors
+
" errors occurred"
);
}
@SupportedAnnotationTypes
(
"*"
)
static
class
AnnoProc
extends
AbstractProcessor
{
public
@Override
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
if
(
roundEnv
.
processingOver
())
{
return
false
;
}
try
{
FileObject
resource
=
processingEnv
.
getFiler
().
getResource
(
StandardLocation
.
SOURCE_PATH
,
"resources"
,
"file.txt"
);
try
{
resource
.
openInputStream
().
close
();
processingEnv
.
getMessager
().
printMessage
(
Kind
.
NOTE
,
"found: "
+
resource
.
toUri
());
return
true
;
}
catch
(
IOException
x
)
{
processingEnv
.
getMessager
().
printMessage
(
Kind
.
ERROR
,
"could not read: "
+
resource
.
toUri
());
x
.
printStackTrace
();
}
}
catch
(
IOException
x
)
{
processingEnv
.
getMessager
().
printMessage
(
Kind
.
ERROR
,
"did not find resource"
);
x
.
printStackTrace
();
}
return
false
;
}
@Override
public
SourceVersion
getSupportedSourceVersion
()
{
return
SourceVersion
.
latest
();
}
}
private
File
write
(
File
dir
,
String
path
,
String
contents
)
throws
IOException
{
File
f
=
new
File
(
dir
,
path
);
f
.
getParentFile
().
mkdirs
();
Writer
w
=
new
FileWriter
(
f
);
try
{
w
.
write
(
contents
);
}
finally
{
w
.
close
();
}
return
f
;
}
void
expect
(
boolean
val
,
boolean
expect
)
{
if
(
val
!=
expect
)
error
(
"Unexpected value: "
+
val
+
"; expected: "
+
expect
);
}
void
error
(
String
msg
)
{
System
.
err
.
println
(
msg
);
errors
++;
}
int
errors
=
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录