diff options
| author | Dani Megert | 2012-04-12 09:35:25 +0000 |
|---|---|---|
| committer | Dani Megert | 2012-04-12 09:35:25 +0000 |
| commit | 18980200e4c26ca26e14ece96f915da84e43001f (patch) | |
| tree | 4c03fd34bd8869526064a357ed72174399909dbb | |
| parent | a8dd14e95dba6829bb0b9153e9c18d01c4f0b80c (diff) | |
| download | eclipse.pde.ui-18980200e4c26ca26e14ece96f915da84e43001f.tar.gz eclipse.pde.ui-18980200e4c26ca26e14ece96f915da84e43001f.tar.xz eclipse.pde.ui-18980200e4c26ca26e14ece96f915da84e43001f.zip | |
Fixed bug 98062: PDE text models don't honor line delimiter preferencesv20120412-0935
8 files changed, 48 insertions, 33 deletions
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/AbstractModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/AbstractModel.java index b4e19494e2..89ae46333c 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/AbstractModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/AbstractModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,24 +12,13 @@ package org.eclipse.pde.internal.core; import java.io.File; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.pde.core.IModel; -import org.eclipse.pde.core.IModelChangedEvent; -import org.eclipse.pde.core.IModelChangedListener; -import org.eclipse.pde.core.ModelChangedEvent; +import java.util.*; +import javax.xml.parsers.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.pde.core.*; import org.xml.sax.SAXException; public abstract class AbstractModel extends PlatformObject implements IModel, IModelChangeProviderExtension, Serializable { @@ -46,6 +35,32 @@ public abstract class AbstractModel extends PlatformObject implements IModel, IM private Exception fException; + protected static String getLineDelimiterPreference(IFile file) { + IScopeContext[] scopeContext; + if (file != null && file.getProject() != null) { + // project preference + scopeContext = new IScopeContext[] {new ProjectScope(file.getProject())}; + String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); + if (lineDelimiter != null) + return lineDelimiter; + } + // workspace preference + scopeContext = new IScopeContext[] {InstanceScope.INSTANCE}; + return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); + } + + protected static String fixLineDelimiter(String string, IFile file) { + String lineDelimiter = getLineDelimiterPreference(file); + if (lineDelimiter == null) + return string; + + String lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$ + if (lineDelimiter.equals(lineSeparator)) + return string; + + return string.replaceAll(lineSeparator, lineDelimiter); + } + public AbstractModel() { fListeners = Collections.synchronizedList(new ArrayList()); } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/build/WorkspaceBuildModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/build/WorkspaceBuildModel.java index 18cfd917a2..959cc4da21 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/build/WorkspaceBuildModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/build/WorkspaceBuildModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -96,7 +96,7 @@ public class WorkspaceBuildModel extends BuildModel implements IEditableModel { return; ByteArrayInputStream stream = null; try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), fUnderlyingResource); stream = new ByteArrayInputStream(contents.getBytes("8859_1")); //$NON-NLS-1$ if (fUnderlyingResource.exists()) { fUnderlyingResource.setContents(stream, false, false, null); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java index b20fec95dc..58740e774e 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -131,7 +131,7 @@ public class WorkspaceBundleModel extends BundleModel implements IEditableModel return; ByteArrayInputStream stream = null; try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), fUnderlyingResource); stream = new ByteArrayInputStream(contents.getBytes("UTF-8")); //$NON-NLS-1$ if (fUnderlyingResource.exists()) { fUnderlyingResource.setContents(stream, false, false, null); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/WorkspaceFeatureModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/WorkspaceFeatureModel.java index 07bd897c08..23dc9a725f 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/WorkspaceFeatureModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/feature/WorkspaceFeatureModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -141,7 +141,7 @@ public class WorkspaceFeatureModel extends AbstractFeatureModel implements IEdit return; ByteArrayInputStream stream = null; try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), file); stream = new ByteArrayInputStream(contents.getBytes("UTF8")); //$NON-NLS-1$ if (file.exists()) { file.setContents(stream, false, false, null); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspaceExtensionsModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspaceExtensionsModel.java index 683d246cbb..0022af472a 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspaceExtensionsModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspaceExtensionsModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -106,7 +106,7 @@ public class WorkspaceExtensionsModel extends AbstractExtensionsModel implements return; ByteArrayInputStream stream = null; try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), fUnderlyingResource); stream = new ByteArrayInputStream(contents.getBytes("UTF8")); //$NON-NLS-1$ if (fUnderlyingResource.exists()) { fUnderlyingResource.setContents(stream, false, false, null); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspacePluginModelBase.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspacePluginModelBase.java index c68781d180..e82af4f395 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspacePluginModelBase.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/WorkspacePluginModelBase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -139,7 +139,7 @@ public abstract class WorkspacePluginModelBase extends AbstractPluginModelBase i return; ByteArrayInputStream stream = null; try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), fUnderlyingResource); stream = new ByteArrayInputStream(contents.getBytes("UTF8")); //$NON-NLS-1$ if (fUnderlyingResource.exists()) { fUnderlyingResource.setContents(stream, false, false, null); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/WorkspaceProductModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/WorkspaceProductModel.java index 505d5a7535..cee2ad336a 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/WorkspaceProductModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/WorkspaceProductModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -94,7 +94,7 @@ public class WorkspaceProductModel extends ProductModel implements IWorkspaceMod public void save() { ByteArrayInputStream stream = null; try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), fFile); stream = new ByteArrayInputStream(contents.getBytes("UTF8")); //$NON-NLS-1$ if (fFile.exists()) { fFile.setContents(stream, false, false, null); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/WorkspaceSiteModel.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/WorkspaceSiteModel.java index e235a7870a..31b25a7e1c 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/WorkspaceSiteModel.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/site/WorkspaceSiteModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -124,7 +124,7 @@ public class WorkspaceSiteModel extends AbstractSiteModel implements IEditableMo public void save() { try { - String contents = getContents(); + String contents = fixLineDelimiter(getContents(), fFile); ByteArrayInputStream stream = new ByteArrayInputStream(contents.getBytes("UTF8")); //$NON-NLS-1$ if (fFile.exists()) { fFile.setContents(stream, false, false, null); |
