Search in sources :

Example 6 with MManifest

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;
}
Also used : MManifest(org.obeonetwork.dsl.manifest.MManifest) Matcher(java.util.regex.Matcher) Attributes(java.util.jar.Attributes) BadVersionStringException(org.obeonetwork.dsl.manifest.BadVersionStringException) ParseException(java.text.ParseException)

Example 7 with MManifest

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);
}
Also used : MManifest(org.obeonetwork.dsl.manifest.MManifest) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) MManifest(org.obeonetwork.dsl.manifest.MManifest) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Session(org.eclipse.sirius.business.api.session.Session)

Example 8 with MManifest

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;
}
Also used : MManifest(org.obeonetwork.dsl.manifest.MManifest) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) MManifest(org.obeonetwork.dsl.manifest.MManifest)

Aggregations

MManifest (org.obeonetwork.dsl.manifest.MManifest)8 Manifest (java.util.jar.Manifest)3 IOException (java.io.IOException)2 Attributes (java.util.jar.Attributes)2 Session (org.eclipse.sirius.business.api.session.Session)2 BadVersionStringException (org.obeonetwork.dsl.manifest.BadVersionStringException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 IProject (org.eclipse.core.resources.IProject)1 ManifestServices (org.obeonetwork.tools.projectlibrary.extension.ManifestServices)1 DependencyRow (org.obeonetwork.tools.projectlibrary.ui.wizard.imp.ImportLibraryIntoProjectWizardModel.DependencyRow)1