mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
Merge pull request #96 from kthoms/kth/bug378980
[378980] Make line delimiter for Manifest configurable by CodeConfig
This commit is contained in:
commit
86dddf8612
7 changed files with 126 additions and 43 deletions
|
@ -50,38 +50,51 @@ public class MergeableManifest extends Manifest {
|
|||
public static final Attributes.Name BUNDLE_LOCALIZATION = new Attributes.Name("Bundle-Localization");
|
||||
public static final Attributes.Name BUNDLE_ACTIVATOR = new Attributes.Name("Bundle-Activator");
|
||||
|
||||
private static final String LINEBREAK = "\r\n";
|
||||
/**
|
||||
* @deprecated Is only used in deprecated static methods.
|
||||
*/
|
||||
@Deprecated
|
||||
private static final String LINEBREAK = Strings.newLine();
|
||||
|
||||
/*
|
||||
* java.util.Manifest throws an exception if line exceeds 512 chars
|
||||
*/
|
||||
/**
|
||||
* @deprecated Use {@link #make512Safe(StringBuffer, String)} instead
|
||||
* @since 2.9
|
||||
*/
|
||||
public static String make512Safe(StringBuffer lines) {
|
||||
if (lines.length() > 512) {
|
||||
StringBuilder result = new StringBuilder(lines.length());
|
||||
String[] splitted = lines.toString().split("\\r?\\n");
|
||||
for(String string: splitted) {
|
||||
if (string.length() > 512) {
|
||||
int idx = 510;
|
||||
StringBuilder temp = new StringBuilder(string);
|
||||
int length = temp.length();
|
||||
while (idx < length - 2) {
|
||||
temp.insert(idx, LINEBREAK+" ");
|
||||
idx += 512;
|
||||
length += 3;
|
||||
}
|
||||
result.append(temp.toString());
|
||||
} else {
|
||||
result.append(string);
|
||||
}
|
||||
result.append(LINEBREAK);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
return lines.toString();
|
||||
}
|
||||
@Deprecated
|
||||
public static String make512Safe(StringBuffer lines) {
|
||||
return make512Safe(lines, LINEBREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.11
|
||||
*/
|
||||
public static String make512Safe(StringBuffer lines, String lineDelimiter) {
|
||||
if (lines.length() > 512) {
|
||||
StringBuilder result = new StringBuilder(lines.length());
|
||||
String[] splitted = lines.toString().split("\\r?\\n");
|
||||
for (String string : splitted) {
|
||||
if (string.length() > 512) {
|
||||
int idx = 510;
|
||||
StringBuilder temp = new StringBuilder(string);
|
||||
int length = temp.length();
|
||||
while (idx < length - 2) {
|
||||
temp.insert(idx, lineDelimiter + " ");
|
||||
idx += 512;
|
||||
length += 3;
|
||||
}
|
||||
result.append(temp.toString());
|
||||
} else {
|
||||
result.append(string);
|
||||
}
|
||||
result.append(lineDelimiter);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
return lines.toString();
|
||||
}
|
||||
|
||||
public class OrderAwareAttributes extends Attributes {
|
||||
|
||||
|
@ -118,7 +131,7 @@ public class MergeableManifest extends Manifest {
|
|||
}
|
||||
|
||||
if (version != null) {
|
||||
out.writeBytes(vername + ": " + version + LINEBREAK);
|
||||
out.writeBytes(vername + ": " + version + lineDelimiter);
|
||||
}
|
||||
|
||||
// write out all attributes except for the version
|
||||
|
@ -137,17 +150,17 @@ public class MergeableManifest extends Manifest {
|
|||
value = new String(vb, 0, 0, vb.length);
|
||||
buffer.append(value);
|
||||
if (it.hasNext())
|
||||
buffer.append(LINEBREAK);
|
||||
out.writeBytes(make512Safe(buffer));
|
||||
buffer.append(lineDelimiter);
|
||||
out.writeBytes(make512Safe(buffer, lineDelimiter));
|
||||
}
|
||||
}
|
||||
}
|
||||
out.writeBytes(LINEBREAK);
|
||||
out.writeBytes(lineDelimiter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copied from base class, but omitted call to make72Safe(buffer)
|
||||
* and does not write empty values
|
||||
* and does not write empty values
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void myWrite(DataOutputStream out) throws IOException {
|
||||
|
@ -163,17 +176,18 @@ public class MergeableManifest extends Manifest {
|
|||
value = new String(vb, 0, 0, vb.length);
|
||||
buffer.append(value);
|
||||
if (it.hasNext())
|
||||
buffer.append(LINEBREAK);
|
||||
out.writeBytes(make512Safe(buffer));
|
||||
buffer.append(lineDelimiter);
|
||||
out.writeBytes(make512Safe(buffer, lineDelimiter));
|
||||
}
|
||||
}
|
||||
out.writeBytes(LINEBREAK);
|
||||
out.writeBytes(lineDelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean modified = false;
|
||||
|
||||
private String projectName;
|
||||
private String lineDelimiter = Strings.newLine();
|
||||
|
||||
public MergeableManifest(InputStream in) throws IOException {
|
||||
try {
|
||||
|
@ -222,7 +236,7 @@ public class MergeableManifest extends Manifest {
|
|||
}
|
||||
String s = (String) getMainAttributes().get(REQUIRE_BUNDLE);
|
||||
Wrapper<Boolean> modified = Wrapper.wrap(this.modified);
|
||||
String result = mergeIntoCommaSeparatedList(s, bundlesToMerge, modified);
|
||||
String result = mergeIntoCommaSeparatedList(s, bundlesToMerge, modified, lineDelimiter);
|
||||
this.modified = modified.get();
|
||||
getMainAttributes().put(REQUIRE_BUNDLE, result);
|
||||
}
|
||||
|
@ -265,6 +279,14 @@ public class MergeableManifest extends Manifest {
|
|||
this.modified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.11
|
||||
*/
|
||||
public void setLineDelimiter (String delimiter) {
|
||||
this.lineDelimiter = delimiter;
|
||||
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
@ -289,8 +311,8 @@ public class MergeableManifest extends Manifest {
|
|||
value = new String(vb, 0, 0, vb.length);
|
||||
}
|
||||
buffer.append(value);
|
||||
buffer.append(LINEBREAK);
|
||||
dos.writeBytes(make512Safe(buffer));
|
||||
buffer.append(lineDelimiter);
|
||||
dos.writeBytes(make512Safe(buffer, lineDelimiter));
|
||||
((OrderAwareAttributes) e.getValue()).myWrite(dos);
|
||||
}
|
||||
dos.flush();
|
||||
|
@ -305,7 +327,7 @@ public class MergeableManifest extends Manifest {
|
|||
public void addExportedPackages(Set<String> packages) {
|
||||
String s = (String) getMainAttributes().get(EXPORT_PACKAGE);
|
||||
Wrapper<Boolean> modified = Wrapper.wrap(this.modified);
|
||||
String result = mergeIntoCommaSeparatedList(s, packages, modified);
|
||||
String result = mergeIntoCommaSeparatedList(s, packages, modified, lineDelimiter);
|
||||
this.modified = modified.get();
|
||||
getMainAttributes().put(EXPORT_PACKAGE, result);
|
||||
}
|
||||
|
@ -325,7 +347,7 @@ public class MergeableManifest extends Manifest {
|
|||
public void addImportedPackages(Set<String> packages) {
|
||||
String s = (String) getMainAttributes().get(IMPORT_PACKAGE);
|
||||
Wrapper<Boolean> modified = Wrapper.wrap(this.modified);
|
||||
String result = mergeIntoCommaSeparatedList(s, packages, modified);
|
||||
String result = mergeIntoCommaSeparatedList(s, packages, modified, lineDelimiter);
|
||||
this.modified = modified.get();
|
||||
getMainAttributes().put(IMPORT_PACKAGE, result);
|
||||
}
|
||||
|
@ -355,7 +377,18 @@ public class MergeableManifest extends Manifest {
|
|||
return resultArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #mergeIntoCommaSeparatedList(String, Set, Wrapper, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static String mergeIntoCommaSeparatedList(String currentString, Set<String> toMergeIn, Wrapper<Boolean> modified) {
|
||||
return mergeIntoCommaSeparatedList(currentString, toMergeIn, modified, LINEBREAK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.11
|
||||
*/
|
||||
public static String mergeIntoCommaSeparatedList(String currentString, Set<String> toMergeIn, Wrapper<Boolean> modified, String lineDelimiter) {
|
||||
String string = currentString == null ? "" : currentString;
|
||||
String[] split = splitQuoteAware(string);
|
||||
Map<String, String> name2parameters = new LinkedHashMap<String, String>();
|
||||
|
@ -389,7 +422,7 @@ public class MergeableManifest extends Manifest {
|
|||
buff.append(";").append(entry.getValue());
|
||||
}
|
||||
if (iterator.hasNext())
|
||||
buff.append(","+LINEBREAK+" ");
|
||||
buff.append(","+lineDelimiter+" ");
|
||||
}
|
||||
String result = buff.toString();
|
||||
return result;
|
||||
|
|
|
@ -71,6 +71,8 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
|
||||
@Inject XtextGeneratorNaming naming
|
||||
|
||||
@Inject CodeConfig codeConfig
|
||||
|
||||
new() {
|
||||
new XtextStandaloneSetup().createInjectorAndDoEMFRegistration()
|
||||
}
|
||||
|
@ -251,6 +253,7 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
try {
|
||||
in = metaInf.readBinaryFile(manifest.path)
|
||||
val merge = new MergeableManifest(in, manifest.bundleName)
|
||||
merge.lineDelimiter = codeConfig.lineDelimiter
|
||||
merge.addExportedPackages(manifest.exportedPackages)
|
||||
merge.addRequiredBundles(manifest.requiredBundles)
|
||||
merge.addImportedPackages(manifest.importedPackages)
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.xtext.util.MergeableManifest
|
|||
import org.eclipse.xtext.util.internal.Log
|
||||
import org.eclipse.xtext.xtext.generator.IGuiceAwareGeneratorComponent
|
||||
import com.google.inject.Injector
|
||||
import org.eclipse.xtext.util.Strings
|
||||
|
||||
@Log
|
||||
@Accessors
|
||||
|
@ -38,6 +39,8 @@ class ManifestAccess extends TextFileAccess implements IGuiceAwareGeneratorCompo
|
|||
|
||||
TypeReference activator
|
||||
|
||||
String lineDelimiter = Strings.newLine();
|
||||
|
||||
new() {
|
||||
path = 'MANIFEST.MF'
|
||||
}
|
||||
|
@ -122,9 +125,10 @@ class ManifestAccess extends TextFileAccess implements IGuiceAwareGeneratorCompo
|
|||
|
||||
override void writeTo(IFileSystemAccess2 fileSystemAccess) {
|
||||
if (fileSystemAccess != null) {
|
||||
val contentToWrite = MergeableManifest.make512Safe(new StringBuffer(content))
|
||||
val contentToWrite = MergeableManifest.make512Safe(new StringBuffer(content), lineDelimiter)
|
||||
// make sure all the constraints for the manifest are respected
|
||||
val mergableManifest = new MergeableManifest(new ByteArrayInputStream(contentToWrite.getBytes("UTF-8")))
|
||||
mergableManifest.lineDelimiter = lineDelimiter
|
||||
var bout = new ByteArrayOutputStream()
|
||||
mergableManifest.write(bout)
|
||||
fileSystemAccess.generateFile(path, new ByteArrayInputStream(bout.toByteArray))
|
||||
|
|
|
@ -9,7 +9,9 @@ package org.eclipse.xtext.xtext.generator.model.project
|
|||
|
||||
import com.google.inject.Injector
|
||||
import java.util.List
|
||||
import javax.inject.Inject
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.xtext.generator.CodeConfig
|
||||
import org.eclipse.xtext.xtext.generator.Issues
|
||||
import org.eclipse.xtext.xtext.generator.model.ManifestAccess
|
||||
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess
|
||||
|
@ -28,6 +30,8 @@ class XtextProjectConfig implements IXtextProjectConfig {
|
|||
SubProjectConfig ideaPlugin = new SubProjectConfig
|
||||
WebProjectConfig web = new WebProjectConfig
|
||||
|
||||
@Inject CodeConfig codeConfig
|
||||
|
||||
def void checkConfiguration(Issues issues) {
|
||||
enabledProjects.forEach[checkConfiguration(issues)]
|
||||
}
|
||||
|
@ -74,7 +78,7 @@ class XtextProjectConfig implements IXtextProjectConfig {
|
|||
}
|
||||
|
||||
protected def newManifestAccess() {
|
||||
new ManifestAccess
|
||||
new ManifestAccess => [lineDelimiter = codeConfig.lineDelimiter]
|
||||
}
|
||||
|
||||
protected def newPluginXmlAccess() {
|
||||
|
|
|
@ -112,6 +112,9 @@ public class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
@Inject
|
||||
private XtextGeneratorNaming naming;
|
||||
|
||||
@Inject
|
||||
private CodeConfig codeConfig;
|
||||
|
||||
public XtextGenerator() {
|
||||
XtextStandaloneSetup _xtextStandaloneSetup = new XtextStandaloneSetup();
|
||||
_xtextStandaloneSetup.createInjectorAndDoEMFRegistration();
|
||||
|
@ -427,6 +430,8 @@ public class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
in = _readBinaryFile;
|
||||
String _bundleName = manifest.getBundleName();
|
||||
final MergeableManifest merge = new MergeableManifest(in, _bundleName);
|
||||
String _lineDelimiter = this.codeConfig.getLineDelimiter();
|
||||
merge.setLineDelimiter(_lineDelimiter);
|
||||
Set<String> _exportedPackages = manifest.getExportedPackages();
|
||||
merge.addExportedPackages(_exportedPackages);
|
||||
Set<String> _requiredBundles = manifest.getRequiredBundles();
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.xtend2.lib.StringConcatenation;
|
|||
import org.eclipse.xtend2.lib.StringConcatenationClient;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.util.MergeableManifest;
|
||||
import org.eclipse.xtext.util.Strings;
|
||||
import org.eclipse.xtext.util.internal.Log;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
|
@ -50,6 +51,8 @@ public class ManifestAccess extends TextFileAccess implements IGuiceAwareGenerat
|
|||
|
||||
private TypeReference activator;
|
||||
|
||||
private String lineDelimiter = Strings.newLine();
|
||||
|
||||
public ManifestAccess() {
|
||||
this.setPath("MANIFEST.MF");
|
||||
}
|
||||
|
@ -251,10 +254,11 @@ public class ManifestAccess extends TextFileAccess implements IGuiceAwareGenerat
|
|||
if (_notEquals) {
|
||||
CharSequence _content = this.getContent();
|
||||
StringBuffer _stringBuffer = new StringBuffer(_content);
|
||||
final String contentToWrite = MergeableManifest.make512Safe(_stringBuffer);
|
||||
final String contentToWrite = MergeableManifest.make512Safe(_stringBuffer, this.lineDelimiter);
|
||||
byte[] _bytes = contentToWrite.getBytes("UTF-8");
|
||||
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_bytes);
|
||||
final MergeableManifest mergableManifest = new MergeableManifest(_byteArrayInputStream);
|
||||
mergableManifest.setLineDelimiter(this.lineDelimiter);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
mergableManifest.write(bout);
|
||||
String _path = this.getPath();
|
||||
|
@ -333,4 +337,13 @@ public class ManifestAccess extends TextFileAccess implements IGuiceAwareGenerat
|
|||
public void setActivator(final TypeReference activator) {
|
||||
this.activator = activator;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getLineDelimiter() {
|
||||
return this.lineDelimiter;
|
||||
}
|
||||
|
||||
public void setLineDelimiter(final String lineDelimiter) {
|
||||
this.lineDelimiter = lineDelimiter;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,15 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import javax.inject.Inject;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xtext.generator.CodeConfig;
|
||||
import org.eclipse.xtext.xtext.generator.Issues;
|
||||
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
|
||||
|
@ -48,6 +52,9 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
|
||||
private WebProjectConfig web = new WebProjectConfig();
|
||||
|
||||
@Inject
|
||||
private CodeConfig codeConfig;
|
||||
|
||||
public void checkConfiguration(final Issues issues) {
|
||||
List<? extends SubProjectConfig> _enabledProjects = this.getEnabledProjects();
|
||||
final Consumer<SubProjectConfig> _function = (SubProjectConfig it) -> {
|
||||
|
@ -116,7 +123,12 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
}
|
||||
|
||||
protected ManifestAccess newManifestAccess() {
|
||||
return new ManifestAccess();
|
||||
ManifestAccess _manifestAccess = new ManifestAccess();
|
||||
final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
|
||||
String _lineDelimiter = this.codeConfig.getLineDelimiter();
|
||||
it.setLineDelimiter(_lineDelimiter);
|
||||
};
|
||||
return ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifestAccess, _function);
|
||||
}
|
||||
|
||||
protected PluginXmlAccess newPluginXmlAccess() {
|
||||
|
@ -189,4 +201,13 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
public void setWeb(final WebProjectConfig web) {
|
||||
this.web = web;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public CodeConfig getCodeConfig() {
|
||||
return this.codeConfig;
|
||||
}
|
||||
|
||||
public void setCodeConfig(final CodeConfig codeConfig) {
|
||||
this.codeConfig = codeConfig;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue