Search in sources :

Example 1 with BadVersionStringException

use of org.obeonetwork.dsl.manifest.BadVersionStringException in project InformationSystem by ObeoNetwork.

the class ManifestServices method getNewManifest.

public MManifest getNewManifest(String id, String version, String comment) {
    MManifest manifest = ManifestFactory.eINSTANCE.createMManifest();
    manifest.setProjectId(id);
    try {
        manifest.setVersion(version);
    } catch (BadVersionStringException e) {
        return null;
    }
    if (comment == null) {
        manifest.setComment("");
    } else {
        manifest.setComment(comment);
    }
    manifest.setCreationDate(new Date());
    return manifest;
}
Also used : MManifest(org.obeonetwork.dsl.manifest.MManifest) BadVersionStringException(org.obeonetwork.dsl.manifest.BadVersionStringException) Date(java.util.Date)

Example 2 with BadVersionStringException

use of org.obeonetwork.dsl.manifest.BadVersionStringException 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 3 with BadVersionStringException

use of org.obeonetwork.dsl.manifest.BadVersionStringException in project InformationSystem by ObeoNetwork.

the class ManifestUtils method getVersionFromString.

public static SemanticVersion getVersionFromString(String versionAsString) throws BadVersionStringException {
    SemanticVersion version = new SemanticVersion();
    Matcher matcher = VERSION_PATTERN.matcher(versionAsString);
    if (matcher.matches()) {
        String major = matcher.group(1);
        String minor = matcher.group(2);
        String patch = matcher.group(3);
        String qualifier = matcher.groupCount() >= 4 ? matcher.group(4) : "";
        try {
            int majorInt = Integer.parseInt(major);
            version.setMajor(majorInt);
        } catch (NumberFormatException e) {
            throw new BadVersionStringException();
        }
        try {
            int minorInt = Integer.parseInt(minor);
            version.setMinor(minorInt);
        } catch (NumberFormatException e) {
            throw new BadVersionStringException();
        }
        try {
            int patchInt = Integer.parseInt(patch);
            version.setPatch(patchInt);
        } catch (NumberFormatException e) {
            throw new BadVersionStringException();
        }
        version.setQualifier(qualifier);
    } else {
        throw new BadVersionStringException();
    }
    return version;
}
Also used : Matcher(java.util.regex.Matcher) BadVersionStringException(org.obeonetwork.dsl.manifest.BadVersionStringException)

Aggregations

BadVersionStringException (org.obeonetwork.dsl.manifest.BadVersionStringException)3 Matcher (java.util.regex.Matcher)2 MManifest (org.obeonetwork.dsl.manifest.MManifest)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Attributes (java.util.jar.Attributes)1