# HG changeset patch # User Alexander Simon # Date 1326362610 -14400 # Node ID 2d3b911642424e09fda6741044afdd2e56289017 # Parent 8bab88d0339583286a77d057797c8410557b84cd fixing Bug #199534 Line Separator is attribute of FileSystem - variant #4 (fixed JG04, JG09-JG11) diff --git a/dlight.remote.impl/nbproject/project.xml b/dlight.remote.impl/nbproject/project.xml --- a/dlight.remote.impl/nbproject/project.xml +++ b/dlight.remote.impl/nbproject/project.xml @@ -85,7 +85,7 @@ - 7.36 + 7.56 diff --git a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObjectBase.java b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObjectBase.java --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObjectBase.java +++ b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObjectBase.java @@ -561,6 +561,9 @@ @Override public Object getAttribute(String attrName) { + if (attrName.equals("default-line-separator")) { // NOI18N + return "\n"; // NOI18N + } if (attrName.equals("isRemoteAndSlow")) { // NOI18N return Boolean.TRUE; } diff --git a/editor.lib/apichanges.xml b/editor.lib/apichanges.xml --- a/editor.lib/apichanges.xml +++ b/editor.lib/apichanges.xml @@ -107,6 +107,23 @@ + + Provides default line separator + + + + + +

+ Defines name of default line separator property + DEFAULT_LINE_SEPARATOR_PROP. + If property getProperty(DEFAULT_LINE_SEPARATOR_PROP) is defined, it will be used instead System.getProperty("line.separator"). + It will be used by the text editor if saving new content to an initially empty file. +

+
+ + +
Deprecating old formatting API diff --git a/editor.lib/nbproject/project.properties b/editor.lib/nbproject/project.properties --- a/editor.lib/nbproject/project.properties +++ b/editor.lib/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.6 -spec.version.base=3.18.0 +spec.version.base=3.19.0 is.autoload=true javadoc.arch=${basedir}/arch.xml diff --git a/editor.lib/nbproject/project.xml b/editor.lib/nbproject/project.xml --- a/editor.lib/nbproject/project.xml +++ b/editor.lib/nbproject/project.xml @@ -141,7 +141,7 @@ - 7.13 + 7.56
diff --git a/editor.lib/src/org/netbeans/editor/BaseDocument.java b/editor.lib/src/org/netbeans/editor/BaseDocument.java --- a/editor.lib/src/org/netbeans/editor/BaseDocument.java +++ b/editor.lib/src/org/netbeans/editor/BaseDocument.java @@ -165,6 +165,13 @@ */ public static final String WRITE_LINE_SEPARATOR_PROP = "write-line-separator"; // NOI18N + /** Default line separator property for writing content into files. + * It will be used by the text editor if saving new content to an initially empty file. + * If it not set the platform default line separator is used. + * @since 3.19 + */ + public static final String DEFAULT_LINE_SEPARATOR_PROP = "default-line-separator"; // NOI18N + /** File name property */ public static final String FILE_NAME_PROP = "file-name"; // NOI18N @@ -1386,7 +1393,10 @@ if (!inited) { // Fill line-separator properties String lineSeparator = ReadWriteUtils.findFirstLineSeparator(buffer); if (lineSeparator == null) { - lineSeparator = ReadWriteUtils.getSystemLineSeparator(); + lineSeparator = (String) getProperty(BaseDocument.DEFAULT_LINE_SEPARATOR_PROP); + if (lineSeparator == null) { + lineSeparator = ReadWriteUtils.getSystemLineSeparator(); + } } putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, lineSeparator); } @@ -1430,7 +1440,10 @@ if (lineSeparator == null) { lineSeparator = (String) getProperty(BaseDocument.READ_LINE_SEPARATOR_PROP); if (lineSeparator == null) { - lineSeparator = ReadWriteUtils.getSystemLineSeparator(); + lineSeparator = (String) getProperty(BaseDocument.DEFAULT_LINE_SEPARATOR_PROP); + if (lineSeparator == null) { + lineSeparator = ReadWriteUtils.getSystemLineSeparator(); + } } } CharSequence docText = (CharSequence) getProperty(CharSequence.class); diff --git a/editor/nbproject/project.xml b/editor/nbproject/project.xml --- a/editor/nbproject/project.xml +++ b/editor/nbproject/project.xml @@ -167,7 +167,7 @@ - 7.55 + 7.56 @@ -261,6 +261,11 @@ + org.netbeans.modules.editor.mimelookup + + + + org.netbeans.modules.editor.mimelookup.impl diff --git a/editor/src/org/netbeans/modules/editor/EditorModule.java b/editor/src/org/netbeans/modules/editor/EditorModule.java --- a/editor/src/org/netbeans/modules/editor/EditorModule.java +++ b/editor/src/org/netbeans/modules/editor/EditorModule.java @@ -637,6 +637,10 @@ final StyledDocument doc = ec.openDocument(); final Reformat reformat = Reformat.get(doc); + String defaultLineSeparator = (String) file.getPrimaryFile().getAttribute(BaseDocument.DEFAULT_LINE_SEPARATOR_PROP); + if (defaultLineSeparator != null) { + doc.putProperty(BaseDocument.DEFAULT_LINE_SEPARATOR_PROP, defaultLineSeparator); + } reformat.lock(); @@ -658,7 +662,12 @@ } finally { reformat.unlock(); - doc.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, ReadWriteUtils.getSystemLineSeparator()); + defaultLineSeparator = (String) doc.getProperty(BaseDocument.DEFAULT_LINE_SEPARATOR_PROP); + if (defaultLineSeparator != null) { + doc.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, defaultLineSeparator); + } else { + doc.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, ReadWriteUtils.getSystemLineSeparator()); + } ec.saveDocument(); } diff --git a/editor/test/unit/src/org/netbeans/modules/editor/LineSeparatorDataEditorSupportTest.java b/editor/test/unit/src/org/netbeans/modules/editor/LineSeparatorDataEditorSupportTest.java new file mode 100644 --- /dev/null +++ b/editor/test/unit/src/org/netbeans/modules/editor/LineSeparatorDataEditorSupportTest.java @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.editor; + +import java.io.File; +import java.io.InputStream; +import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.StyledDocument; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.api.editor.mimelookup.test.MockMimeLookup; +import org.netbeans.junit.MockServices; +import org.netbeans.junit.NbTestCase; +import org.openide.cookies.EditorCookie; +import org.openide.filesystems.*; +import org.openide.loaders.DataObject; +import org.openide.util.Exceptions; +import org.openide.util.NbPreferences; + +/** + * + * @author Alexander Simon + */ +public class LineSeparatorDataEditorSupportTest extends NbTestCase { + private MimePath textMimePath; + + static { + System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false"); + } + + public LineSeparatorDataEditorSupportTest(String s) { + super(s); + } + + @Override + protected void setUp() throws Exception { + MockServices.setServices(new Class[]{MockMimeLookup.class}); + textMimePath = MimePath.parse("text/plain"); + MockMimeLookup.setInstances(textMimePath, new NbEditorKit(), NbPreferences.forModule(getClass())); + } + + public void testLineSeparator() throws Exception { + File file = File.createTempFile("lineSeparator", ".txt", getWorkDir()); + FileObject fileObject = FileUtil.toFileObject(file); + fileObject.setAttribute("default-line-separator", "\r"); + DataObject dataObject = DataObject.find(fileObject); + EditorCookie editor = dataObject.getLookup().lookup(org.openide.cookies.EditorCookie.class); + final StyledDocument doc = editor.openDocument(); + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + try { + doc.insertString(doc.getLength(), ".\n", null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + }); + + editor.saveDocument(); + InputStream inputStream = fileObject.getInputStream(); + assertEquals('.',inputStream.read()); + assertEquals('\r',inputStream.read()); + } +} diff --git a/openide.filesystems/apichanges.xml b/openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml +++ b/openide.filesystems/apichanges.xml @@ -49,6 +49,24 @@ Filesystems API + + + Provides default line separator + + + + + +

+ File object can provide default line separator if it differs from System.getProperty("line.separator"). + Call fo.getAttribute("default-line-separator") return string with default line separator. + Default line separator will be used by the text editor if saving new content to an initially empty file. + Any other code which creates file content programmatically must manually read this property if it cares. +

+
+ + +
Introduced FileObject.revert diff --git a/openide.filesystems/manifest.mf b/openide.filesystems/manifest.mf --- a/openide.filesystems/manifest.mf +++ b/openide.filesystems/manifest.mf @@ -2,5 +2,5 @@ OpenIDE-Module: org.openide.filesystems OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml -OpenIDE-Module-Specification-Version: 7.55 +OpenIDE-Module-Specification-Version: 7.56 diff --git a/openide.loaders/manifest.mf b/openide.loaders/manifest.mf --- a/openide.loaders/manifest.mf +++ b/openide.loaders/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.loaders -OpenIDE-Module-Specification-Version: 7.34 +OpenIDE-Module-Specification-Version: 7.35 OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0 OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml diff --git a/openide.loaders/nbproject/project.xml b/openide.loaders/nbproject/project.xml --- a/openide.loaders/nbproject/project.xml +++ b/openide.loaders/nbproject/project.xml @@ -122,7 +122,7 @@ - 7.55 + 7.56
diff --git a/openide.loaders/src/org/openide/text/DataEditorSupport.java b/openide.loaders/src/org/openide/text/DataEditorSupport.java --- a/openide.loaders/src/org/openide/text/DataEditorSupport.java +++ b/openide.loaders/src/org/openide/text/DataEditorSupport.java @@ -125,6 +125,13 @@ /** error manager for CloneableEditorSupport logging and error reporting */ static final Logger ERR = Logger.getLogger("org.openide.text.DataEditorSupport"); // NOI18N + /** Default line separator property for writing content into files. + * It will be used by the text editor if saving new content to an initially empty file. + * Any other code which creates file content programmatically must manually read this property if it cares. + * If it not set the platform default line separator is used. + */ + private static final String DEFAULT_LINE_SEPARATOR_PROP = "default-line-separator"; // NOI18N + /** Which data object we are associated with */ private final DataObject obj; /** listener to associated node's events */ @@ -480,6 +487,7 @@ c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile()); } final FileObject fo = this.getDataObject().getPrimaryFile(); + doc.putProperty(DEFAULT_LINE_SEPARATOR_PROP, fo.getAttribute(DEFAULT_LINE_SEPARATOR_PROP)); final Reader r; if (warnedEncodingFiles.contains(fo)) { r = new InputStreamReader (stream, c);