Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorTran Le2012-10-29 18:25:30 +0000
committerTran Le2012-10-29 18:25:30 +0000
commite6008d071075605bd63684be308b41229baa2c6e (patch)
treee39255b404be5633353a4e9cc919e956b73fdc5c /common
parent57b6dcc572d02bcd9303526050ac36fbed0c27ae (diff)
downloadwebtools.dali-e6008d071075605bd63684be308b41229baa2c6e.tar.gz
webtools.dali-e6008d071075605bd63684be308b41229baa2c6e.tar.xz
webtools.dali-e6008d071075605bd63684be308b41229baa2c6e.zip
389940 - Metamodel generation should use appropriate text file line
delimiters
Diffstat (limited to 'common')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java15
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/BodySourceWriter.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java20
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java58
4 files changed, 90 insertions, 9 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java
index a283b1bc9a..dbe9ea76cc 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java
@@ -21,10 +21,13 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.JptWorkspace;
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.osgi.framework.Bundle;
/**
@@ -237,6 +240,18 @@ public class PlatformTools {
}
+ // ********** workspace preferences **********
+
+ public static String getNewTextFileLineDelimiter() {
+ IScopeContext[] contexts = new IScopeContext[] { DefaultScope.INSTANCE };
+ return Platform.getPreferencesService().getString(
+ Platform.PI_RUNTIME,
+ Platform.PREF_LINE_SEPARATOR,
+ StringTools.CR,
+ contexts);
+ }
+
+
// ********** disabled constructor **********
private PlatformTools() {
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/BodySourceWriter.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/BodySourceWriter.java
index 53a76d601b..0ac5b50f4b 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/BodySourceWriter.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/BodySourceWriter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -41,8 +41,8 @@ public class BodySourceWriter
// key = short class name; value = import package
protected final HashMap<String, ImportPackage> imports = new HashMap<String, ImportPackage>();
- public BodySourceWriter(String packageName, String className) {
- super(new StringWriter(2000));
+ public BodySourceWriter(String packageName, String className, String lineSeparator) {
+ super(new StringWriter(2000), DEFAULT_INDENT, lineSeparator);
this.packageName = packageName;
this.className = className;
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java
index 06cfbdf396..d42d789f7f 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/IndentingPrintWriter.java
@@ -9,11 +9,11 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.io;
-import java.io.PrintWriter;
import java.io.Writer;
+import org.eclipse.jpt.common.utility.internal.StringTools;
/**
- * Extend {@link PrintWriter} to automatically indent new lines.
+ * Extend {@link JptPrintWriter} to automatically indent new lines.
* <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
@@ -22,7 +22,7 @@ import java.io.Writer;
* will almost certainly be broken (repeatedly) as the API evolves.
*/
public class IndentingPrintWriter
- extends PrintWriter
+ extends JptPrintWriter
{
private final String indent;
private int indentLevel;
@@ -35,14 +35,18 @@ public class IndentingPrintWriter
* Construct a writer that indents with tabs.
*/
public IndentingPrintWriter(Writer out) {
- this(out, DEFAULT_INDENT);
+ this(out, DEFAULT_INDENT, StringTools.CR);
}
/**
* Construct a writer that indents with the specified string.
*/
public IndentingPrintWriter(Writer out, String indent) {
- this(out, indent, 0);
+ this(out, indent, 0, StringTools.CR);
+ }
+
+ public IndentingPrintWriter(Writer out, String indent, String lineSeparator) {
+ this(out, indent, 0, lineSeparator);
}
/**
@@ -50,7 +54,11 @@ public class IndentingPrintWriter
* and begins with the specified indent level.
*/
public IndentingPrintWriter(Writer out, String indent, int initialIndentLevel) {
- super(out);
+ this(out, indent, initialIndentLevel, StringTools.CR);
+ }
+
+ public IndentingPrintWriter(Writer out, String indent, int initialIndentLevel, String lineSeparator) {
+ super(out, lineSeparator);
if (indent == null) {
throw new NullPointerException();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java
new file mode 100644
index 0000000000..9973fdb71a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/io/JptPrintWriter.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.io;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Extend {@link PrintWriter} to give the option to select a line separator.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public class JptPrintWriter
+ extends PrintWriter
+{
+ private String lineSeparator;
+
+ public JptPrintWriter(Writer out) {
+ this(out, StringTools.CR); // use system property by default
+ }
+
+ public JptPrintWriter(Writer out, String lineSeparator) {
+ super(out);
+ this.lineSeparator = lineSeparator;
+ }
+
+ @Override
+ public void println() {
+ try {
+ synchronized (this.lock) {
+ if (this.out == null) {
+ throw new IOException("Stream closed"); //$NON-NLS-1$
+ }
+ this.out.write(this.lineSeparator);
+ }
+ }
+ catch (InterruptedIOException e) {
+ Thread.currentThread().interrupt();
+ }
+ catch (IOException e) {
+ this.setError();
+ }
+ }
+}

Back to the top