[#1321] Do not override icons when regenerate.

Signed-off-by: Arne Deutsch <Arne.Deutsch@itemis.de>
This commit is contained in:
Arne Deutsch 2019-12-12 13:51:30 +01:00
parent 35c544fa81
commit 9d9137ef66
6 changed files with 57 additions and 20 deletions

View file

@ -35,5 +35,12 @@ class BinaryFileAccess {
fileSystemAccess.generateFile(path, new ByteArrayInputStream(internalContents))
}
}
def existIn(IXtextGeneratorFileSystemAccess fileSystemAccess) {
if (fileSystemAccess === null) {
return false
}
return fileSystemAccess.isFile(path)
}
}

View file

@ -95,7 +95,7 @@ class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
</perspectiveExtension>
</extension>
'''
if (generateToolbarButton) {
projectConfig.eclipsePlugin.pluginXml.entries += '''
<extension
@ -171,12 +171,15 @@ class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
def generateDefaultIcons() {
val projectTemplate = fileAccessFactory.createBinaryFile("file_template.png")
projectTemplate.content = readBinaryFileFromPackage("file_template.png")
projectTemplate.writeTo(projectConfig.eclipsePlugin.icons)
if (!projectTemplate.existIn(projectConfig.eclipsePlugin.icons)) {
projectTemplate.content = readBinaryFileFromPackage("file_template.png")
projectTemplate.writeTo(projectConfig.eclipsePlugin.icons)
}
val newProject = fileAccessFactory.createBinaryFile("new_" + grammar.simpleName + "_file.png")
newProject.content = readBinaryFileFromPackage("new_xfile.png")
newProject.writeTo(projectConfig.eclipsePlugin.icons)
if (!newProject.existIn(projectConfig.eclipsePlugin.icons)) {
newProject.content = readBinaryFileFromPackage("new_xfile.png")
newProject.writeTo(projectConfig.eclipsePlugin.icons)
}
}
private def byte[] readBinaryFileFromPackage(String fileName) {

View file

@ -111,7 +111,7 @@ class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragment {
</perspectiveExtension>
</extension>
'''
if (generateToolbarButton) {
projectConfig.eclipsePlugin.pluginXml.entries += '''
<extension
@ -244,12 +244,15 @@ class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragment {
def generateDefaultIcons() {
val projectTemplate = fileAccessFactory.createBinaryFile("project_template.png")
projectTemplate.content = readBinaryFileFromPackage("project_template.png")
projectTemplate.writeTo(projectConfig.eclipsePlugin.icons)
if (!projectTemplate.existIn(projectConfig.eclipsePlugin.icons)) {
projectTemplate.content = readBinaryFileFromPackage("project_template.png")
projectTemplate.writeTo(projectConfig.eclipsePlugin.icons)
}
val newProject = fileAccessFactory.createBinaryFile("new_" + grammar.simpleName + "_proj.gif")
newProject.content = readBinaryFileFromPackage("new_xproj.gif")
newProject.writeTo(projectConfig.eclipsePlugin.icons)
if (!newProject.existIn(projectConfig.eclipsePlugin.icons)) {
newProject.content = readBinaryFileFromPackage("new_xproj.gif")
newProject.writeTo(projectConfig.eclipsePlugin.icons)
}
}
private def byte[] readBinaryFileFromPackage(String fileName) {

View file

@ -12,6 +12,7 @@ import java.util.Arrays;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.generator.IFileSystemAccess2;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess;
/**
* A utility class for generating binary files.
@ -38,6 +39,13 @@ public class BinaryFileAccess {
}
}
public boolean existIn(final IXtextGeneratorFileSystemAccess fileSystemAccess) {
if ((fileSystemAccess == null)) {
return false;
}
return fileSystemAccess.isFile(this.path);
}
@Pure
public String getPath() {
return this.path;

View file

@ -403,14 +403,22 @@ public class TemplateFileWizardFragment extends AbstractXtextGeneratorFragment {
public void generateDefaultIcons() {
final BinaryFileAccess projectTemplate = this.fileAccessFactory.createBinaryFile("file_template.png");
projectTemplate.setContent(this.readBinaryFileFromPackage("file_template.png"));
projectTemplate.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _existIn = projectTemplate.existIn(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _not = (!_existIn);
if (_not) {
projectTemplate.setContent(this.readBinaryFileFromPackage("file_template.png"));
projectTemplate.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
}
String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
String _plus = ("new_" + _simpleName);
String _plus_1 = (_plus + "_file.png");
final BinaryFileAccess newProject = this.fileAccessFactory.createBinaryFile(_plus_1);
newProject.setContent(this.readBinaryFileFromPackage("new_xfile.png"));
newProject.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _existIn_1 = newProject.existIn(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _not_1 = (!_existIn_1);
if (_not_1) {
newProject.setContent(this.readBinaryFileFromPackage("new_xfile.png"));
newProject.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
}
}
private byte[] readBinaryFileFromPackage(final String fileName) {

View file

@ -606,14 +606,22 @@ public class TemplateProjectWizardFragment extends AbstractXtextGeneratorFragmen
public void generateDefaultIcons() {
final BinaryFileAccess projectTemplate = this.fileAccessFactory.createBinaryFile("project_template.png");
projectTemplate.setContent(this.readBinaryFileFromPackage("project_template.png"));
projectTemplate.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _existIn = projectTemplate.existIn(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _not = (!_existIn);
if (_not) {
projectTemplate.setContent(this.readBinaryFileFromPackage("project_template.png"));
projectTemplate.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
}
String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
String _plus = ("new_" + _simpleName);
String _plus_1 = (_plus + "_proj.gif");
final BinaryFileAccess newProject = this.fileAccessFactory.createBinaryFile(_plus_1);
newProject.setContent(this.readBinaryFileFromPackage("new_xproj.gif"));
newProject.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _existIn_1 = newProject.existIn(this.getProjectConfig().getEclipsePlugin().getIcons());
boolean _not_1 = (!_existIn_1);
if (_not_1) {
newProject.setContent(this.readBinaryFileFromPackage("new_xproj.gif"));
newProject.writeTo(this.getProjectConfig().getEclipsePlugin().getIcons());
}
}
private byte[] readBinaryFileFromPackage(final String fileName) {