Commit 1537b53a authored by Jan Belle's avatar Jan Belle
Browse files

[ui] Fix new set of eTrice models wizard

Bug 552051

Change-Id: I4ae58063d9f2b554adaba394c1b8813fe55a631c
parent ad0bc76a
......@@ -18,6 +18,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
......@@ -29,17 +30,17 @@ import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.emf.common.util.URI;
import org.eclipse.etrice.generator.ui.wizard.ProjectCreator;
import org.eclipse.etrice.generator.ui.wizard.WizardHelpers;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.dialogs.IOverwriteQuery;
......@@ -52,8 +53,8 @@ import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
*/
public class CProjectConfigurator extends ProjectConfigurator {
private static final String C_MODELLIB_NAME = "etrice_c_modellib";
private static final String C_RUNTIME_FOLDER_NAME = "etrice_c_runtime";
private static final String C_MODELLIB_FOLDER_NAME = "etrice_modellib";
private static final String C_RUNTIME_FOLDER_NAME = "etrice_runtime";
/* (non-Javadoc)
* @see org.eclipse.etrice.generator.ui.cdt.ProjectConfigurator#isApplicable(org.eclipse.core.resources.IProject)
......@@ -133,6 +134,22 @@ public class CProjectConfigurator extends ProjectConfigurator {
return IOverwriteQuery.ALL;
}
};
@Override
protected void configureModelpath(IProject project, IPath path) {
if(!project.getFile("modelpath").exists()) {
List<String> srcDirs = new ArrayList<>();
IPath dir = path.removeFirstSegments(1);
if(!dir.isEmpty()) {
srcDirs.add(dir.toPortableString());
}
if(isCopyRuntime()) {
srcDirs.add(C_MODELLIB_FOLDER_NAME + "/model");
}
URI modelpathURI = URI.createPlatformResourceURI(project.getFullPath().append("modelpath").toPortableString(), false);
ProjectCreator.createModelpathDescription(modelpathURI, srcDirs, Collections.emptyList());
}
}
/*
* (non-Javadoc)
......@@ -262,42 +279,17 @@ public class CProjectConfigurator extends ProjectConfigurator {
}
if (current!=null) {
children = structureProvider.getChildren(current);
IPath modelFolderPath = getPath();
for (Object child : children) {
if (child instanceof ZipEntry) {
if (! ((ZipEntry) child).isDirectory()) {
ImportOperation importOperation = new ImportOperation(
modelFolderPath,
child,
structureProvider,
OVERWRITE_ALL_QUERY);
importOperation.setContext(null);
importOperation.run(SubMonitor.convert(progressMonitor, 1));
}
ImportOperation importOperation = new ImportOperation(
project.getFullPath().append(C_MODELLIB_FOLDER_NAME),
child,
structureProvider,
OVERWRITE_ALL_QUERY);
importOperation.setContext(null);
importOperation.run(SubMonitor.convert(progressMonitor, 1));
}
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IContainer modelFolder = root.getFolder(modelFolderPath.append("model"));
final IPath newPath = modelFolder.getFullPath().removeLastSegments(1).append(C_MODELLIB_NAME);
ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory().createRule(modelFolder);
WorkspaceModifyOperation operation = new WorkspaceModifyOperation(rule) {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
modelFolder.move(newPath, true, monitor);
}
};
try {
operation.run(progressMonitor);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
......
......@@ -59,6 +59,7 @@ public abstract class ProjectConfigurator implements IProjectConfigurator {
protected abstract Map<String, String> getProjectRefInfo(ICConfigurationDescription configDescription, String toolChain);
protected abstract void copyRuntime(IProject project, IProgressMonitor progressMonitor, String platform);
protected abstract void customizeBuildConfig(IProject project, IConfiguration buildConfig);
protected abstract void configureModelpath(IProject project, IPath path);
@Override
public void configure(IProject project, IPath path, boolean copyRuntime, String platform, IProgressMonitor progressMonitor) {
......@@ -71,7 +72,7 @@ public abstract class ProjectConfigurator implements IProjectConfigurator {
if (copyRuntime) {
copyRuntime(project, progressMonitor, platform);
}
configureModelpath(project, path);
configureIncludesAndLibraries(project, progressMonitor);
}
}
......@@ -186,5 +187,5 @@ public abstract class ProjectConfigurator implements IProjectConfigurator {
setting.setSettingEntries(kind, allEntries);
}
}
......@@ -25,14 +25,6 @@ public class GeneratorPreferencePage
public void createFieldEditors() {
addLabel("");
addField(
new RadioGroupFieldEditor(
PreferenceConstants.BUILD_KIND,
"Choose the build kind that is used for eTrice Java applications:",
1,
new String[][] { { "&Maven", PreferenceConstants.MAVEN }, {
"&JDT", PreferenceConstants.JDT }
}, getFieldEditorParent()));
addField(
new BooleanFieldEditor(
PreferenceConstants.GEN_USE_TRANSLATION,
......
......@@ -10,10 +10,4 @@ public class PreferenceConstants {
public static final String GEN_USE_TRANSLATION = "GenerateUsingTranslation";
public static final String GEN_OLD_STYLE_TRANSITION_DATA = "GenerateOldStyleTransitionData";
/**
* The kind of build with the two possibilities {@link #MAVEN} and {@link #JDT}
*/
public static final String BUILD_KIND = "BuildKind";
public static final String MAVEN = "Maven";
public static final String JDT = "JDT";
}
......@@ -16,7 +16,6 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
*/
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getInstance().getPreferenceStore();
store.setDefault(PreferenceConstants.BUILD_KIND, PreferenceConstants.JDT);
store.setDefault(PreferenceConstants.GEN_DIR, "src-gen");
store.setDefault(PreferenceConstants.GEN_DOC_DIR, "doc-gen");
store.setDefault(PreferenceConstants.GEN_USE_TRANSLATION, true);
......
......@@ -137,10 +137,7 @@ public class EmptyProjectWizard extends Wizard implements INewWizard {
String projectName = project.getName();
URI projectURI = URI.createPlatformResourceURI(projectName, true);
String modelName = MODEL_NAME;
ProjectCreator.createBuildProperties(projectURI.appendSegment("build.properties"), modelName);
ProjectCreator.createLaunchGeneratorConfig(projectURI.appendSegment("generate_Template.launch"),
"java", "/" + projectName + "/model", "Mapping", AbstractGeneratorOptions.MAIN_NAME.getDefaultValue(), additionalLaunchConfigLines);
......
......@@ -346,21 +346,6 @@ public class ProjectCreator {
writeFile(uri, ProjectFileFragments.getBasicMappingModel(baseName));
}
public static void createBuildProperties(URI uri, String baseName) {
try {
PrintStream prop = new PrintStream(
URIConverter.INSTANCE.createOutputStream(uri, null), false,
"UTF-8");
prop.println("source.. = src/,\\");
prop.println("src-gen/");
prop.close();
} catch (UnsupportedEncodingException e) {
Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e);
} catch (IOException e) {
Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e);
}
}
public static void createLaunchGeneratorConfig(URI uri, String targetLanguage, String modelPath, String mappingName,
String mainMethodName, String[] addLines) {
writeFile(uri, ProjectFileFragments.getGeneratorLaunchConfig(targetLanguage, modelPath, mappingName, mainMethodName, addLines));
......@@ -401,6 +386,10 @@ public class ProjectCreator {
project.getName());
}
}
public static void createModelpathDescription(URI uri, Iterable<String> srcDirs, Iterable<String> projects) {
writeFile(uri, ProjectFileFragments.getModelpathDescription(srcDirs, projects));
}
/**
* @param project
......
......@@ -146,4 +146,14 @@ class ProjectFileFragments {
</launchConfiguration>
'''
}
def static String getModelpathDescription(Iterable<String> srcDirs, Iterable<String> projects) '''
FOR s : srcDirs
srcDir s
ENDFOR
FOR p : projects
project p
ENDFOR
'''
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment