Search in sources :

Example 1 with DeclaredVersion

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());
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) DeclaredVersion(org.eclipse.n4js.n4mf.DeclaredVersion) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) IProjectDescription(org.eclipse.core.resources.IProjectDescription) SourceFragment(org.eclipse.n4js.n4mf.SourceFragment)

Example 2 with DeclaredVersion

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;
}
Also used : DeclaredVersion(org.eclipse.n4js.n4mf.DeclaredVersion) StringJoiner(java.util.StringJoiner)

Example 3 with DeclaredVersion

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;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) DeclaredVersion(org.eclipse.n4js.n4mf.DeclaredVersion)

Example 4 with DeclaredVersion

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;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) DeclaredVersion(org.eclipse.n4js.n4mf.DeclaredVersion)

Example 5 with DeclaredVersion

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;
}
Also used : DeclaredVersion(org.eclipse.n4js.n4mf.DeclaredVersion)

Aggregations

DeclaredVersion (org.eclipse.n4js.n4mf.DeclaredVersion)7 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)2 SourceFragment (org.eclipse.n4js.n4mf.SourceFragment)2 IOException (java.io.IOException)1 StringJoiner (java.util.StringJoiner)1 IFile (org.eclipse.core.resources.IFile)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IResource (org.eclipse.core.resources.IResource)1 URI (org.eclipse.emf.common.util.URI)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 BootstrapModule (org.eclipse.n4js.n4mf.BootstrapModule)1 ExecModule (org.eclipse.n4js.n4mf.ExecModule)1 ExtendedRuntimeEnvironment (org.eclipse.n4js.n4mf.ExtendedRuntimeEnvironment)1 ImplementedProjects (org.eclipse.n4js.n4mf.ImplementedProjects)1 InitModules (org.eclipse.n4js.n4mf.InitModules)1 ModuleFilter (org.eclipse.n4js.n4mf.ModuleFilter)1 ModuleFilterSpecifier (org.eclipse.n4js.n4mf.ModuleFilterSpecifier)1