use of org.eclipse.n4js.n4mf.DeclaredVersion in project n4js by eclipse.
the class ProjectTestsUtils method createManifestN4MFFile.
/**
* @param manifestAdjustments
* before saving the manifest this procedure will be called to allow adjustments to the manifest's
* properties (the ProjectDescription object passed to the procedure will already contain all default
* values). May be <code>null</code> if no adjustments are required.
*/
public static void createManifestN4MFFile(IProject project, String sourceFolder, String outputFolder, Consumer<ProjectDescription> manifestAdjustments) throws CoreException {
IFile config = project.getFile("manifest.n4mf");
URI uri = URI.createPlatformResourceURI(config.getFullPath().toString(), true);
ProjectDescription projectDesc = N4mfFactory.eINSTANCE.createProjectDescription();
projectDesc.setProjectDependencies(N4mfFactory.eINSTANCE.createProjectDependencies());
projectDesc.setDeclaredVendorId("org.eclipse.n4js");
projectDesc.setVendorName("Eclipse N4JS Project");
projectDesc.setProjectId(project.getName());
projectDesc.setProjectType(ProjectType.LIBRARY);
DeclaredVersion projectVersion = N4mfFactory.eINSTANCE.createDeclaredVersion();
projectVersion.setMajor(0);
projectVersion.setMinor(0);
projectVersion.setMicro(1);
projectDesc.setProjectVersion(projectVersion);
projectDesc.setOutputPath(outputFolder);
SourceFragment sourceProjectPath = N4mfFactory.eINSTANCE.createSourceFragment();
sourceProjectPath.setSourceFragmentType(SourceFragmentType.SOURCE);
sourceProjectPath.getPaths().add(sourceFolder);
projectDesc.getSourceFragment().add(sourceProjectPath);
if (manifestAdjustments != null)
manifestAdjustments.accept(projectDesc);
ResourceSet rs = createResourceSet(project);
Resource res = rs.createResource(uri);
res.getContents().add(projectDesc);
// Workaround to avoid any unnecessary warnings due to empty project dependency block
if (projectDesc.getAllProjectDependencies().isEmpty()) {
projectDesc.setProjectDependencies(null);
}
try {
res.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
project.refreshLocal(IResource.DEPTH_INFINITE, monitor());
waitForAutoBuild();
Assert.assertTrue("manifest.n4mf should have been created", config.exists());
}
use of org.eclipse.n4js.n4mf.DeclaredVersion in project n4js by eclipse.
the class ExternalLibraryPreferencePage method parsingVersionValidator.
/**
* version validator based on N4MF parser (and its support for version syntax).
*/
private String parsingVersionValidator(final String data) {
String result = null;
ParserResults<DeclaredVersion> parseResult = ManifestValuesParsingUtil.parseDeclaredVersion(data);
if (!parseResult.getErrors().isEmpty()) {
// collect just parse errors
StringJoiner joinedMessage = new StringJoiner("\n");
parseResult.getErrors().forEach((String msg) -> joinedMessage.add(msg));
result = joinedMessage.toString();
} else {
// even if there are no parse errors check if version instance was create correctly
if (parseResult.getAST() == null) {
result = "Could not create version from string :" + data;
}
}
return result;
}
use of org.eclipse.n4js.n4mf.DeclaredVersion in project n4js by eclipse.
the class VersionConstraintImpl method basicSetUpperVersion.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetUpperVersion(DeclaredVersion newUpperVersion, NotificationChain msgs) {
DeclaredVersion oldUpperVersion = upperVersion;
upperVersion = newUpperVersion;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4mfPackage.VERSION_CONSTRAINT__UPPER_VERSION, oldUpperVersion, newUpperVersion);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.n4js.n4mf.DeclaredVersion in project n4js by eclipse.
the class VersionConstraintImpl method basicSetLowerVersion.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetLowerVersion(DeclaredVersion newLowerVersion, NotificationChain msgs) {
DeclaredVersion oldLowerVersion = lowerVersion;
lowerVersion = newLowerVersion;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4mfPackage.VERSION_CONSTRAINT__LOWER_VERSION, oldLowerVersion, newLowerVersion);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.n4js.n4mf.DeclaredVersion in project n4js by eclipse.
the class NpmExporterUtil method versionAsSemverString.
/**
* Converts a {@link DeclaredVersion} from an {@link IN4JSProject} into the form "0.0.0" - leaves out the
* {@link DeclaredVersion#getQualifier()}.
*/
public static final String versionAsSemverString(IN4JSProject project) {
final char sep = '.';
final char hyphon = '-';
final DeclaredVersion ver = project.getVersion();
final String verStr = "" + ver.getMajor() + sep + ver.getMinor() + sep + ver.getMicro();
if (ver.getQualifier() != null)
return verStr + hyphon + ver.getQualifier();
return verStr;
}
Aggregations