diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2009-12-08 12:52:32 +0000 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2009-12-08 12:52:32 +0000 |
commit | e7c1ecb1e6de811843afaac78ad370a67b69563e (patch) | |
tree | a5fca1015e4999c507ce7b5fd662d99ca0ee53a0 /org.rtems.cdt/src/org/rtems/cdt/Storage.java | |
parent | Update to version 1.4.0. (diff) | |
download | rtems-eclipse-plug-in-master.tar.bz2 |
* src/org/rtems/cdt/Activator.java, src/org/rtems/cdt/Constants.java,
src/org/rtems/cdt/Storage.java,
src/org/rtems/cdt/VolatilePreferenceStore.java,
src/org/rtems/cdt/build/CommandLineGenerator.java,
src/org/rtems/cdt/build/CygwinScannerInfoCollector.java,
src/org/rtems/cdt/build/EnvironmentSupplier.java,
src/org/rtems/cdt/build/RunScannerInfoProvider.java,
src/org/rtems/cdt/preferences/PreferenceInitializer.java,
src/org/rtems/cdt/preferences/PreferencePage.java,
src/org/rtems/cdt/properties/PropertyPage.java,
src/org/rtems/cdt/wizards/BasicSetup.java,
src/org/rtems/cdt/wizards/FinishSetup.java: Replaced '( ' with '('.
Diffstat (limited to 'org.rtems.cdt/src/org/rtems/cdt/Storage.java')
-rw-r--r-- | org.rtems.cdt/src/org/rtems/cdt/Storage.java | 218 |
1 files changed, 109 insertions, 109 deletions
diff --git a/org.rtems.cdt/src/org/rtems/cdt/Storage.java b/org.rtems.cdt/src/org/rtems/cdt/Storage.java index e0cc1a5..6827c8d 100644 --- a/org.rtems.cdt/src/org/rtems/cdt/Storage.java +++ b/org.rtems.cdt/src/org/rtems/cdt/Storage.java @@ -60,15 +60,15 @@ public class Storage { private static final int TOOL_COMPLETE = 3; - public static String getPreference( String key) { - return Activator.getDefault().getPreferenceStore().getString( key); + public static String getPreference(String key) { + return Activator.getDefault().getPreferenceStore().getString(key); } - public static String getPristineProperty( IProject project, String key) { + public static String getPristineProperty(IProject project, String key) { String value = null; try { - value = project.getPersistentProperty( new QualifiedName( "", key)); + value = project.getPersistentProperty(new QualifiedName("", key)); } catch (CoreException e) { e.printStackTrace(); } @@ -76,51 +76,51 @@ public class Storage { return value; } - public static String getProperty( IProject project, String key) { - String value = getPristineProperty( project, key); + public static String getProperty(IProject project, String key) { + String value = getPristineProperty(project, key); if (value == null) { - if (key.startsWith( Constants.TOOL_KEY_PREFIX)) { - changePlatform( project, Constants.PLATFORM_DEFAULT); + if (key.startsWith(Constants.TOOL_KEY_PREFIX)) { + changePlatform(project, Constants.PLATFORM_DEFAULT); } else { - value = getPreference( key); - setProperty( project, key, value); + value = getPreference(key); + setProperty(project, key, value); } } return value; } - public static void setProperty( IProject project, String key, String value) { + public static void setProperty(IProject project, String key, String value) { try { - project.setPersistentProperty( new QualifiedName( "", key), value); + project.setPersistentProperty(new QualifiedName("", key), value); } catch (CoreException e) { e.printStackTrace(); } } - public static IConfiguration [] getConfigurations( IProject project) { - ICProjectDescription pd = CoreModel.getDefault().getProjectDescription( project); + public static IConfiguration [] getConfigurations(IProject project) { + ICProjectDescription pd = CoreModel.getDefault().getProjectDescription(project); ICConfigurationDescription cds [] = pd.getConfigurations(); IConfiguration cfgs [] = new IConfiguration [cds.length]; for (int i = 0; i < cds.length; ++i) { - cfgs [i] = ManagedBuildManager.getConfigurationForDescription( cds [i]); + cfgs [i] = ManagedBuildManager.getConfigurationForDescription(cds [i]); } return cfgs; } - public static IConfiguration getActiveConfiguration( IProject project) { - ICProjectDescription pd = CoreModel.getDefault().getProjectDescription( project); + public static IConfiguration getActiveConfiguration(IProject project) { + ICProjectDescription pd = CoreModel.getDefault().getProjectDescription(project); ICConfigurationDescription cd = pd.getActiveConfiguration(); - IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription( cd); + IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cd); return cfg; } - public static String prependToPath( String path, String part) { + public static String prependToPath(String path, String part) { if (path == null || path.length()==0) { return part; } else { @@ -128,52 +128,52 @@ public class Storage { } } - public static String prependToPathByPreference( String path, String key) { - String basePath = getPreference( key); + public static String prependToPathByPreference(String path, String key) { + String basePath = getPreference(key); if (basePath != null) { - IPath part = new Path( basePath).append( "bin"); + IPath part = new Path(basePath).append("bin"); - return prependToPath( path, part.toOSString()); + return prependToPath(path, part.toOSString()); } return path; } - public static String prependToPathByProperty( IProject project, String path, String key) { - String basePath = getProperty( project, key); + public static String prependToPathByProperty(IProject project, String path, String key) { + String basePath = getProperty(project, key); if (basePath != null) { - IPath part = new Path( basePath).append( "bin"); + IPath part = new Path(basePath).append("bin"); - return prependToPath( path, part.toOSString()); + return prependToPath(path, part.toOSString()); } return path; } - public static String getPlatform( IProject project) { - return getPristineProperty( project, Constants.PLATFORM_KEY); + public static String getPlatform(IProject project) { + return getPristineProperty(project, Constants.PLATFORM_KEY); } - public static void setPlatform( IProject project, String platform) { - setProperty( project, Constants.PLATFORM_KEY, platform); + public static void setPlatform(IProject project, String platform) { + setProperty(project, Constants.PLATFORM_KEY, platform); } - public static void clearPlatform( IProject project) { - setPlatform( project, null); + public static void clearPlatform(IProject project) { + setPlatform(project, null); // Delete discovered paths for all configurations of the project - for (IConfiguration cfg : getConfigurations( project)) { + for (IConfiguration cfg : getConfigurations(project)) { CfgDiscoveredPathManager.getInstance().removeDiscoveredInfo( project, - new CfgInfoContext( cfg) + new CfgInfoContext(cfg) ); } } - public static void changePlatform( IProject project, String newPlatform) { - String platform = getPlatform( project); + public static void changePlatform(IProject project, String newPlatform) { + String platform = getPlatform(project); // Check if we have already the requested platform if (platform != null && platform == newPlatform) { @@ -182,74 +182,74 @@ public class Storage { } // Set new platform - setPlatform( project, newPlatform); + setPlatform(project, newPlatform); // Update path prepends String path = null; - if (Platform.getOS().equals( Platform.OS_WIN32)) { - if (newPlatform.equals( Constants.PLATFORM_CYGWIN)) { - path = prependToPathByPreference( path, Constants.CYGWIN_PATH_KEY); + if (Platform.getOS().equals(Platform.OS_WIN32)) { + if (newPlatform.equals(Constants.PLATFORM_CYGWIN)) { + path = prependToPathByPreference(path, Constants.CYGWIN_PATH_KEY); } else { - path = prependToPathByPreference( path, Constants.MINGW_PATH_KEY); - path = prependToPathByPreference( path, Constants.MSYS_PATH_KEY); + path = prependToPathByPreference(path, Constants.MINGW_PATH_KEY); + path = prependToPathByPreference(path, Constants.MSYS_PATH_KEY); } } - path = prependToPathByProperty( project, path, Constants.BASE_PATH_KEY); - setProperty( project, Constants.PATH_PREPEND_KEY, path); + path = prependToPathByProperty(project, path, Constants.BASE_PATH_KEY); + setProperty(project, Constants.PATH_PREPEND_KEY, path); // Update tools - updateTools( project, newPlatform); + updateTools(project, newPlatform); } - private static void updateTools( IProject project, String platform) { - String bspPath = getProperty( project, Constants.BSP_PATH_KEY); - IPath make = new Path( "make"); + private static void updateTools(IProject project, String platform) { + String bspPath = getProperty(project, Constants.BSP_PATH_KEY); + IPath make = new Path("make"); List<String> options = new LinkedList<String>(); boolean error = false; // Set tools to default values - updateTool( project, Constants.TOOL_ARCHIVER_KEY, "ar", options); - updateTool( project, Constants.TOOL_ASSEMBLER_KEY, "as", options); - updateTool( project, Constants.TOOL_COMPILER_CPP_KEY, "g++", options); - updateTool( project, Constants.TOOL_COMPILER_C_KEY, "gcc", options); - updateTool( project, Constants.TOOL_LINKER_CPP_KEY, "g++", options); - updateTool( project, Constants.TOOL_LINKER_C_KEY, "gcc", options); + updateTool(project, Constants.TOOL_ARCHIVER_KEY, "ar", options); + updateTool(project, Constants.TOOL_ASSEMBLER_KEY, "as", options); + updateTool(project, Constants.TOOL_COMPILER_CPP_KEY, "g++", options); + updateTool(project, Constants.TOOL_COMPILER_C_KEY, "gcc", options); + updateTool(project, Constants.TOOL_LINKER_CPP_KEY, "g++", options); + updateTool(project, Constants.TOOL_LINKER_C_KEY, "gcc", options); // Delete markers for this unit - deleteMarkers( project, Constants.MARKER_ID_TOOL_DISCOVERY); + deleteMarkers(project, Constants.MARKER_ID_TOOL_DISCOVERY); // Translate path if necessary - if (Platform.getOS().equals( Platform.OS_WIN32)) { - if (platform.equals( Constants.PLATFORM_CYGWIN)) { - String s [] = bspPath.split( ":"); + if (Platform.getOS().equals(Platform.OS_WIN32)) { + if (platform.equals(Constants.PLATFORM_CYGWIN)) { + String s [] = bspPath.split(":"); if (s.length > 0) { - bspPath = bspPath.replaceFirst( "^" + s [0] + ":", "/cygdrive/" + s [0]); + bspPath = bspPath.replaceFirst("^" + s [0] + ":", "/cygdrive/" + s [0]); } } - bspPath = bspPath.replaceAll( "\\\\", "/"); + bspPath = bspPath.replaceAll("\\\\", "/"); } // Create make process builder ProcessBuilder pb = new ProcessBuilder(); // Change working directory to the Makefile location - pb.directory( Activator.getDefault().getMakefileLocation().toFile()); + pb.directory(Activator.getDefault().getMakefileLocation().toFile()); // Update path environment variable Map<String, String> env = pb.environment(); - String path = env.get( Constants.PATH_VARIABLE_NAME); - String part = getProperty( project, Constants.PATH_PREPEND_KEY); - path = Storage.prependToPath( path, part); - env.put( Constants.PATH_VARIABLE_NAME, path); + String path = env.get(Constants.PATH_VARIABLE_NAME); + String part = getProperty(project, Constants.PATH_PREPEND_KEY); + path = Storage.prependToPath(path, part); + env.put(Constants.PATH_VARIABLE_NAME, path); // On Windows we have to search for the make program in the new path environment - if (Platform.getOS().equals( Platform.OS_WIN32)) { - String parts [] = path.split( Constants.PATH_SEPARATOR); + if (Platform.getOS().equals(Platform.OS_WIN32)) { + String parts [] = path.split(Constants.PATH_SEPARATOR); boolean found = false; for (String p : parts) { - IPath makeCandidate = new Path( p).append( "make.exe"); - File file = new File( makeCandidate.toOSString()); + IPath makeCandidate = new Path(p).append("make.exe"); + File file = new File(makeCandidate.toOSString()); if (file.exists()) { make = makeCandidate; @@ -268,7 +268,7 @@ public class Storage { } // Set command line - String makeArgument = Constants.BSP_PATH_MAKE_VARIABLE + "=" + bspPath.replaceAll( " ", "\\\\ "); + String makeArgument = Constants.BSP_PATH_MAKE_VARIABLE + "=" + bspPath.replaceAll(" ", "\\\\ "); pb.command( make.toOSString(), makeArgument @@ -279,7 +279,7 @@ public class Storage { try { p = pb.start(); InputStream is = p.getInputStream(); - BufferedReader br = new BufferedReader( new InputStreamReader( is)); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = br.readLine(); String key = null; String command = null; @@ -287,19 +287,19 @@ public class Storage { while (line != null) { switch (state) { case EXPECT_OPTION: - if (line.startsWith( VALUE_START_TOKEN)) { - options.add( line.substring( 1)); + if (line.startsWith(VALUE_START_TOKEN)) { + options.add(line.substring(1)); } else { state = TOOL_COMPLETE; continue; } break; case EXPECT_COMMAND: - if (line.startsWith( VALUE_START_TOKEN)) { - command = line.substring( 1); + if (line.startsWith(VALUE_START_TOKEN)) { + command = line.substring(1); state = EXPECT_OPTION; } else { - throw new IOException( "unexpected line format"); + throw new IOException("unexpected line format"); } break; case EXPECT_KEY: @@ -307,21 +307,21 @@ public class Storage { key = line; state = EXPECT_COMMAND; } else { - throw new IOException( "unexpected line format"); + throw new IOException("unexpected line format"); } break; case TOOL_COMPLETE: - updateTool( project, key, command, options); + updateTool(project, key, command, options); options.clear(); state = EXPECT_KEY; continue; default: - throw new IOException( "unexpected state"); + throw new IOException("unexpected state"); } line = br.readLine(); } if (state == EXPECT_OPTION) { - updateTool( project, key, command, options); + updateTool(project, key, command, options); } } catch (IOException e) { error = true; @@ -356,18 +356,18 @@ public class Storage { // Check error if (error) { // Clear platform to trigger an update again if someone changed a preference or property value - setPlatform( project, null); + setPlatform(project, null); } } - private static void updateTool( IProject project, String toolKey, String command, List<String> options) { + private static void updateTool(IProject project, String toolKey, String command, List<String> options) { List<String> filteredOptions = new LinkedList<String>(); // Filter options - if (toolKey.startsWith( Constants.COMPILER_KEY_PREFIX) || toolKey.startsWith( Constants.LINKER_KEY_PREFIX)) { + if (toolKey.startsWith(Constants.COMPILER_KEY_PREFIX) || toolKey.startsWith(Constants.LINKER_KEY_PREFIX)) { for (String option : options) { - if (!(option.length() == 0 || option.trim().matches( "^(-c|-O[0123s]|-g.*|-W[\\w-]*|[-]*pipe)$"))) { - filteredOptions.add( option); + if (!(option.length() == 0 || option.trim().matches("^(-c|-O[0123s]|-g.*|-W[\\w-]*|[-]*pipe)$"))) { + filteredOptions.add(option); } } } else { @@ -377,11 +377,11 @@ public class Storage { // Transform filtered option list into option string value String optionsValue = new String(); if (!options.isEmpty()) { - optionsValue = filteredOptions.get( 0); - filteredOptions.remove( 0); + optionsValue = filteredOptions.get(0); + filteredOptions.remove(0); } for (String option : filteredOptions) { - if (option.indexOf( ' ') != -1) { + if (option.indexOf(' ') != -1) { option = "\"" + option + "\""; } optionsValue += OPTION_SEPARATOR + option; @@ -391,49 +391,49 @@ public class Storage { // It is also a workaround for the internal builder since this one does not care about // the environment provider to fix the $PATH. IPath commandPath = new Path( - Storage.getProperty( project, Constants.BASE_PATH_KEY) + Storage.getProperty(project, Constants.BASE_PATH_KEY) ) - .append( "bin") - .append( command); + .append("bin") + .append(command); command = commandPath.toString(); // Set properties - setProperty( project, toolKey, command); - setProperty( project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX, optionsValue); + setProperty(project, toolKey, command); + setProperty(project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX, optionsValue); } - public static String [] getToolOptions( IProject project, String toolKey) { - String optionsValue = getProperty( project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX); + public static String [] getToolOptions(IProject project, String toolKey) { + String optionsValue = getProperty(project, toolKey + Constants.TOOL_OPTIONS_KEY_POSTFIX); - return optionsValue.split( OPTION_SEPARATOR); + return optionsValue.split(OPTION_SEPARATOR); } - public static boolean areToolOptionsEnabled( IProject project) { - return !getProperty( project, Constants.DISABLE_TOOL_OPTIONS_KEY).equals( "true"); + public static boolean areToolOptionsEnabled(IProject project) { + return !getProperty(project, Constants.DISABLE_TOOL_OPTIONS_KEY).equals("true"); } - public static void createMarker( IProject project, String id, String message) { - createMarker( project, id, message, IMarker.SEVERITY_ERROR); + public static void createMarker(IProject project, String id, String message) { + createMarker(project, id, message, IMarker.SEVERITY_ERROR); } - public static void createMarker( IProject project, String id, String message, int severity) { + public static void createMarker(IProject project, String id, String message, int severity) { try { - IMarker marker = project.createMarker( IMarker.PROBLEM); - marker.setAttribute( IMarker.LOCATION, id); - marker.setAttribute( IMarker.MESSAGE, message); - marker.setAttribute( IMarker.SEVERITY, severity); + IMarker marker = project.createMarker(IMarker.PROBLEM); + marker.setAttribute(IMarker.LOCATION, id); + marker.setAttribute(IMarker.MESSAGE, message); + marker.setAttribute(IMarker.SEVERITY, severity); } catch (CoreException e) { e.printStackTrace(); } } - public static void deleteMarkers( IProject project, String id) { + public static void deleteMarkers(IProject project, String id) { try { - IMarker[] markers = project.findMarkers( IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); + IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); if (markers != null) { for (IMarker m : markers) { - if (m.getResource().equals( project) && m.getAttribute( IMarker.LOCATION, "").equals( id)) { + if (m.getResource().equals(project) && m.getAttribute(IMarker.LOCATION, "").equals(id)) { m.delete(); } } |