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;
}
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;
}
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;
}
Aggregations