Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
ed8d5030
Commit
ed8d5030
authored
Jan 29, 2018
by
Florian Hölzl
Browse files
Added RCP-specific file reader for plugin resources.
refs 3250
parent
ea62f1fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.generator.common/trunk/src/org/fortiss/af3/generator/common/utils/SourceModelElementFactory.java
View file @
ed8d5030
...
...
@@ -15,16 +15,19 @@
+--------------------------------------------------------------------------*/
package
org.fortiss.af3.generator.common.utils
;
import
static
org
.
conqat
.
lib
.
commons
.
filesystem
.
FileSystemUtils
.
readFileBinary
;
import
static
org
.
eclipse
.
core
.
runtime
.
FileLocator
.
toFileURL
;
import
static
org
.
eclipse
.
core
.
runtime
.
Platform
.
getBundle
;
import
static
org
.
fortiss
.
af3
.
generator
.
common
.
model
.
source
.
AF3GeneratorCommonLanguagesSourceFactory
.
eINSTANCE
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
org.conqat.lib.commons.filesystem.FileSystemUtils
;
import
org.eclipse.core.runtime.FileLocator
;
import
org.
eclipse.core.runtime.Platform
;
import
org.
fortiss.af3.generator.common.model.c.CSourcePackage
;
import
org.fortiss.af3.generator.common.model.source.AF3GeneratorCommonLanguagesSourcePackage
;
import
org.fortiss.af3.generator.common.model.source.ByteContentUnit
;
import
org.fortiss.af3.generator.common.model.source.SourcePackage
;
...
...
@@ -83,7 +86,11 @@ public class SourceModelElementFactory {
*
* @return {@link ByteContentUnit} with the content taken from a file contained in the given
* plugin.
* @deprecated this method does not work properly in an RCP product. Use
* {@link #createByteContentUnitForPluginFileInRCP(CSourcePackage, String, String)},
* instead.
*/
@Deprecated
public
static
ByteContentUnit
createByteContentUnitForPluginFile
(
String
pluginID
,
String
relativePath
,
String
filename
,
boolean
executable
)
throws
IOException
,
URISyntaxException
{
...
...
@@ -91,10 +98,50 @@ public class SourceModelElementFactory {
if
(
relativePath
!=
null
&&
!
""
.
equals
(
relativePath
.
trim
()))
{
loc
=
relativePath
+
File
.
separator
+
filename
;
}
Bundle
b
=
Platform
.
getBundle
(
pluginID
);
Bundle
b
=
getBundle
(
pluginID
);
URL
fileURL
=
b
.
getEntry
(
loc
);
File
contentFile
=
new
File
(
FileLocator
.
resolve
(
fileURL
).
toURI
());
byte
[]
content
=
FileSystemUtils
.
readFileBinary
(
contentFile
);
byte
[]
content
=
readFileBinary
(
contentFile
);
return
createByteContentUnit
(
filename
,
content
,
executable
);
}
/**
* Creates a {@link ByteContentUnit} with the content taken from a file contained in the given
* plugin.
*
* @param pluginID
* the plugin ID to search for the file
* @param relativePath
* the relative path within the plugin
* @param filename
* the filename to be used to pull the byte content
* @param executable
* the executable flag of the created byte content unit
*
* @return {@link ByteContentUnit} with the content taken from a file contained in the given
* plugin.
*/
public
static
ByteContentUnit
createByteContentUnitForPluginFileInRCP
(
String
pluginID
,
String
relativePath
,
String
filename
,
boolean
executable
)
{
String
loc
=
filename
;
if
(
relativePath
!=
null
&&
!
""
.
equals
(
relativePath
.
trim
()))
{
loc
=
relativePath
+
File
.
separator
+
filename
;
}
try
{
Bundle
bundle
=
getBundle
(
pluginID
);
URL
fileURL
=
bundle
.
getEntry
(
loc
);
URL
resolvedFileURL
=
toFileURL
(
fileURL
);
// IMPORTANT: use this three parameter constructor with null as third argument
URI
resolvedURI
=
new
URI
(
resolvedFileURL
.
getProtocol
(),
resolvedFileURL
.
getPath
(),
null
);
File
file
=
new
File
(
resolvedURI
);
byte
[]
content
=
readFileBinary
(
file
);
return
createByteContentUnit
(
filename
,
content
,
executable
);
}
catch
(
URISyntaxException
e1
)
{
e1
.
printStackTrace
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
return
null
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment