use of org.obeonetwork.dsl.manifest.MManifest in project InformationSystem by ObeoNetwork.
the class ManifestServices method getModelFromMarManifest.
public MManifest getModelFromMarManifest(Manifest manifest) {
MManifest manifestModel = ManifestFactory.eINSTANCE.createMManifest();
manifestModel.setProjectId(manifest.getMainAttributes().getValue(new Attributes.Name(MANIFEST_KEY_PROJECT_ID)));
String creationDateAsString = manifest.getMainAttributes().getValue(new Attributes.Name(MANIFEST_KEY_EXPORT_DATE));
if (creationDateAsString != null) {
try {
manifestModel.setCreationDate(DATE_FORMAT.parse(creationDateAsString));
} catch (ParseException e) {
// Do nothing, date format is invalid
}
}
manifestModel.setComment(manifest.getMainAttributes().getValue(new Attributes.Name(MANIFEST_KEY_EXPORT_COMMENT)));
try {
manifestModel.setVersion(manifest.getMainAttributes().getValue(new Attributes.Name(MANIFEST_KEY_EXPORT_VERSION)));
} catch (BadVersionStringException e) {
}
String dependenciesAsString = manifest.getMainAttributes().getValue(new Attributes.Name(MANIFEST_KEY_EXPORT_DEPENDENCIES));
String[] dependencies = dependenciesAsString.split(",");
for (String dep : dependencies) {
Matcher matcher = DEPENDENCY_REGEX.matcher(dep);
if (matcher.matches()) {
String id = matcher.group(1);
String version = matcher.group(2);
if (ManifestUtils.isVersionFormatValid(version)) {
MManifest depManifest = ManifestFactory.eINSTANCE.createMManifest();
depManifest.setProjectId(id);
try {
depManifest.setVersion(version);
} catch (BadVersionStringException e) {
// Do nothing, should never occur as we have checked just before
}
manifestModel.getDependencies().add(depManifest);
}
}
}
return manifestModel;
}
use of org.obeonetwork.dsl.manifest.MManifest in project InformationSystem by ObeoNetwork.
the class ProjectLibraryExporter method export.
/**
* Export a modeling project as an archive containing a manifest
* @param project Modeling project to export
* @param projectId ID of project in archive
* @param version Version of exported project
* @param comment
* @param targetFile
*/
public void export(ModelingProject project, String projectId, String version, String comment, File targetFile) {
// 1st step: create a new manifest
MManifest newManifest = manifestServices.getNewManifest(projectId, version, comment);
// 2nd step: zip project's contents into target file
IProject iProject = project.getProject();
File projectFolder = iProject.getLocation().toFile();
try {
FileOutputStream outputStream = new FileOutputStream(targetFile);
// Zip folder contents
ZipUtils.zipFolder(projectFolder, outputStream);
outputStream.close();
// 3rd step: generate add MANIFEST.MF to file
Manifest marManifest = manifestServices.getMarManifestFromModel(newManifest);
// And add it to zip
addMarManifestToArchive(marManifest, targetFile);
} catch (IOException e) {
// TODO
}
// 4th step: save manifest into AIRD for future references
Session session = project.getSession();
manifestServices.addExportedManifestToSession(session, newManifest);
}
use of org.obeonetwork.dsl.manifest.MManifest in project InformationSystem by ObeoNetwork.
the class ManifestServices method getMarManifestFromModel.
public Manifest getMarManifestFromModel(MManifest manifestModel) {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(new Attributes.Name(MANIFEST_KEY_PROJECT_ID), manifestModel.getProjectId());
manifest.getMainAttributes().put(new Attributes.Name(MANIFEST_KEY_EXPORT_VERSION), manifestModel.getVersion());
manifest.getMainAttributes().put(new Attributes.Name(MANIFEST_KEY_EXPORT_DATE), DATE_FORMAT.format(manifestModel.getCreationDate()));
manifest.getMainAttributes().put(new Attributes.Name(MANIFEST_KEY_EXPORT_COMMENT), manifestModel.getComment());
String dependencies = "";
for (MManifest requiredManifest : manifestModel.getDependencies()) {
String dependencyAsString = String.format(DEPENDENCY_PATTERN, requiredManifest.getProjectId(), requiredManifest.getVersion());
dependencies += dependencyAsString + ",";
}
manifest.getMainAttributes().put(new Attributes.Name(MANIFEST_KEY_EXPORT_DEPENDENCIES), dependencies);
return manifest;
}
Aggregations