3737public class SvdPathResolver implements IDynamicVariableResolver
3838{
3939
40+ private static final ILaunchBarManager LAUNCH_BAR_MANAGER = Activator .getService (ILaunchBarManager .class );
41+
4042 public String resolveValue (IDynamicVariable variable , String argument ) throws CoreException
4143 {
4244 String selectedTarget = StringUtil .EMPTY ;
4345 String selectedTargetPath = StringUtil .EMPTY ;
4446 try
4547 {
46- ILaunchBarManager launchBarManager = Activator .getService (ILaunchBarManager .class );
47- selectedTarget = launchBarManager .getActiveLaunchTarget ().getAttribute (IDFLaunchConstants .ATTR_IDF_TARGET ,
48+ selectedTarget = LAUNCH_BAR_MANAGER .getActiveLaunchTarget ().getAttribute (IDFLaunchConstants .ATTR_IDF_TARGET ,
4849 StringUtil .EMPTY );
4950 if (StringUtil .isEmpty (selectedTarget ))
5051 return StringUtil .EMPTY ;
51- URL svdUrl = Platform .getBundle (Activator .PLUGIN_ID )
52- .getResource ("svd/" .concat (selectedTarget .concat (".svd" ))); //$NON-NLS-1$ //$NON-NLS-2$
53- String jarPath = new File (TabSvdTarget .class .getProtectionDomain ().getCodeSource ().getLocation ().toURI ())
54- .getPath ();
55- if (!jarPath .contains (".jar" )) //$NON-NLS-1$
56- {
57- selectedTargetPath = new File (FileLocator .resolve (svdUrl ).toURI ()).getPath ();
58- }
59- else
60- {
61- IProject project = EclipseUtils
62- .getProjectByLaunchConfiguration (launchBarManager .getActiveLaunchConfiguration ());
63- IFolder svdFolder = project .getFolder (IDFConstants .BUILD_FOLDER ).getFolder ("svd" ); //$NON-NLS-1$
64- if (!svdFolder .exists ())
65- {
66- svdFolder .create (true , true , new NullProgressMonitor ());
67- }
68- IFile svdFile = project .getFolder (IDFConstants .BUILD_FOLDER ).getFile (svdUrl .getPath ());
69- if (!svdFile .exists ())
70- {
71- JarFile jarFile = new JarFile (jarPath );
72- JarEntry file = (JarEntry ) jarFile .getEntry (svdUrl .getFile ().substring (1 ));
73- if (file != null )
74- {
75- InputStream inputStream = jarFile .getInputStream (file );
76- svdFile .create (inputStream , true , new NullProgressMonitor ());
77- inputStream .close ();
78- }
79- jarFile .close ();
80- }
81- project .refreshLocal (IProject .DEPTH_INFINITE , new NullProgressMonitor ());
82- selectedTargetPath = svdFile .getRawLocation ().toOSString ();
83- }
52+ selectedTargetPath = resolveSvdPath (selectedTarget );
8453 }
8554 catch (Exception e )
8655 {
@@ -89,4 +58,45 @@ public String resolveValue(IDynamicVariable variable, String argument) throws Co
8958 return selectedTargetPath ;
9059 }
9160
61+ private String resolveSvdPath (String target ) throws Exception
62+ {
63+ URL svdUrl = Platform .getBundle (Activator .PLUGIN_ID ).getResource ("svd/" .concat (target .concat (".svd" ))); //$NON-NLS-1$ //$NON-NLS-2$
64+ String jarPath = new File (TabSvdTarget .class .getProtectionDomain ().getCodeSource ().getLocation ().toURI ())
65+ .getPath ();
66+ String selectedTargetPath ;
67+ if (!jarPath .contains (".jar" )) //$NON-NLS-1$
68+ selectedTargetPath = new File (FileLocator .resolve (svdUrl ).toURI ()).getPath ();
69+ else
70+ selectedTargetPath = resolveSvdPathFromJar (svdUrl , jarPath );
71+ return selectedTargetPath ;
72+ }
73+
74+ private String resolveSvdPathFromJar (URL svdUrl , String jarPath ) throws Exception
75+ {
76+ IProject project = EclipseUtils
77+ .getProjectByLaunchConfiguration (LAUNCH_BAR_MANAGER .getActiveLaunchConfiguration ());
78+ IFolder svdFolder = project .getFolder (IDFConstants .BUILD_FOLDER ).getFolder ("svd" ); //$NON-NLS-1$
79+ if (!svdFolder .exists ())
80+ {
81+ svdFolder .create (true , true , new NullProgressMonitor ());
82+ }
83+ IFile svdFile = project .getFolder (IDFConstants .BUILD_FOLDER ).getFile (svdUrl .getPath ());
84+ if (!svdFile .exists ())
85+ {
86+ try (JarFile jarFile = new JarFile (jarPath ))
87+ {
88+ JarEntry file = (JarEntry ) jarFile .getEntry (svdUrl .getFile ().substring (1 ));
89+ if (file != null )
90+ {
91+ InputStream inputStream = jarFile .getInputStream (file );
92+ svdFile .create (inputStream , true , new NullProgressMonitor ());
93+ inputStream .close ();
94+ }
95+ }
96+ }
97+ project .refreshLocal (IProject .DEPTH_INFINITE , new NullProgressMonitor ());
98+ return svdFile .getRawLocation ().toOSString ();
99+ }
100+
101+
92102}
0 commit comments