Search in sources :

Example 6 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method addNatureToProject.

private static void addNatureToProject(IProject project, String natureId) throws Exception {
    if (project.hasNature(JavaCore.NATURE_ID)) {
        return;
    }
    IProjectDescription description = project.getDescription();
    String[] prevNatures = description.getNatureIds();
    String[] newNatures = Arrays.copyOf(prevNatures, prevNatures.length + 1);
    newNatures[prevNatures.length] = natureId;
    description.setNatureIds(newNatures);
    project.setDescription(description, null);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 7 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.

the class DemosImportTest method createTempDemoProject.

protected void createTempDemoProject(String demoName) throws CoreException, PersistenceException {
    Project projectInfor = new Project();
    projectInfor.setLabel(demoName);
    projectInfor.setDescription("no desc");
    projectInfor.setLanguage(ECodeLanguage.JAVA);
    User user = PropertiesFactory.eINSTANCE.createUser();
    user.setLogin("testauto@talend.com");
    projectInfor.setAuthor(user);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
    IProject prj = root.getProject(technicalLabel);
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        IProjectDescription desc = null;
        if (prj.exists()) {
            // always delete to avoid conflicts between 2 tests
            prj.delete(true, null);
        }
        desc = workspace.newProjectDescription(technicalLabel);
        desc.setNatureIds(new String[] { TalendNature.ID });
        desc.setComment(projectInfor.getDescription());
        prj.create(desc, null);
        prj.open(IResource.DEPTH_INFINITE, null);
        prj.setDefaultCharset("UTF-8", null);
    } catch (CoreException e) {
        throw new PersistenceException(e);
    }
    tempDemoProject = new Project();
    // Fill project object
    tempDemoProject.setLabel(projectInfor.getLabel());
    tempDemoProject.setDescription(projectInfor.getDescription());
    tempDemoProject.setLanguage(projectInfor.getLanguage());
    tempDemoProject.setAuthor(projectInfor.getAuthor());
    tempDemoProject.setLocal(true);
    tempDemoProject.setTechnicalLabel(technicalLabel);
    XmiResourceManager xmiResourceManager = new XmiResourceManager();
    Resource projectResource = xmiResourceManager.createProjectResource(prj);
    projectResource.getContents().add(tempDemoProject.getEmfProject());
    projectResource.getContents().add(tempDemoProject.getAuthor());
    xmiResourceManager.saveResource(projectResource);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Example 8 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.

the class AddContextCommentValueMigrationTaskTest method createTempProject.

private static void createTempProject() throws CoreException, PersistenceException, LoginException {
    Project projectInfor = new Project();
    projectInfor.setLabel("testauto");
    projectInfor.setDescription("no desc");
    projectInfor.setLanguage(ECodeLanguage.JAVA);
    User user = PropertiesFactory.eINSTANCE.createUser();
    user.setLogin("testauto@talend.com");
    projectInfor.setAuthor(user);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
    IProject prj = root.getProject(technicalLabel);
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        IProjectDescription desc = null;
        if (prj.exists()) {
            // always delete to avoid conflicts between 2 tests
            prj.delete(true, null);
        }
        desc = workspace.newProjectDescription(technicalLabel);
        desc.setNatureIds(new String[] { TalendNature.ID });
        desc.setComment(projectInfor.getDescription());
        prj.create(desc, null);
        prj.open(IResource.DEPTH_INFINITE, null);
        prj.setDefaultCharset("UTF-8", null);
    } catch (CoreException e) {
        throw new PersistenceException(e);
    }
    sampleProject = new Project();
    // Fill project object
    sampleProject.setLabel(projectInfor.getLabel());
    sampleProject.setDescription(projectInfor.getDescription());
    sampleProject.setLanguage(projectInfor.getLanguage());
    sampleProject.setAuthor(projectInfor.getAuthor());
    sampleProject.setLocal(true);
    sampleProject.setTechnicalLabel(technicalLabel);
    XmiResourceManager xmiResourceManager = new XmiResourceManager();
    Resource projectResource = xmiResourceManager.createProjectResource(prj);
    projectResource.getContents().add(sampleProject.getEmfProject());
    projectResource.getContents().add(sampleProject.getAuthor());
    xmiResourceManager.saveResource(projectResource);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Example 9 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project tdi-studio-se by Talend.

the class FixUnevenItemContextParametersMigrationTaskTest method createTempProject.

private static void createTempProject() throws CoreException, PersistenceException, LoginException {
    Project projectInfor = new Project();
    projectInfor.setLabel("testauto");
    projectInfor.setDescription("no desc");
    projectInfor.setLanguage(ECodeLanguage.JAVA);
    User user = PropertiesFactory.eINSTANCE.createUser();
    user.setLogin("testauto@talend.com");
    projectInfor.setAuthor(user);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
    IProject prj = root.getProject(technicalLabel);
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        IProjectDescription desc = null;
        if (prj.exists()) {
            // always delete to avoid conflicts between 2 tests
            prj.delete(true, null);
        }
        desc = workspace.newProjectDescription(technicalLabel);
        desc.setNatureIds(new String[] { TalendNature.ID });
        desc.setComment(projectInfor.getDescription());
        prj.create(desc, null);
        prj.open(IResource.DEPTH_INFINITE, null);
        prj.setDefaultCharset("UTF-8", null);
    } catch (CoreException e) {
        throw new PersistenceException(e);
    }
    sampleProject = new Project();
    // Fill project object
    sampleProject.setLabel(projectInfor.getLabel());
    sampleProject.setDescription(projectInfor.getDescription());
    sampleProject.setLanguage(projectInfor.getLanguage());
    sampleProject.setAuthor(projectInfor.getAuthor());
    sampleProject.setLocal(true);
    sampleProject.setTechnicalLabel(technicalLabel);
    XmiResourceManager xmiResourceManager = new XmiResourceManager();
    Resource projectResource = xmiResourceManager.createProjectResource(prj);
    projectResource.getContents().add(sampleProject.getEmfProject());
    projectResource.getContents().add(sampleProject.getAuthor());
    xmiResourceManager.saveResource(projectResource);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Example 10 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project ow by vtst.

the class Utils method setProjectBuilder.

/**
   * Set or remove a builder to a project.
   * @param project  The project.
   * @param builderName  The ID of the builder.
   * @param status  true to set the builder, false to remove it.
   * @throws CoreException
   */
public static void setProjectBuilder(IProject project, String builderName, boolean status) throws CoreException {
    IProjectDescription description = project.getDescription();
    ICommand[] commands = description.getBuildSpec();
    int i;
    for (i = 0; i < commands.length; ++i) {
        if (commands[i].getBuilderName().equals(builderName))
            break;
    }
    if (status == (i < commands.length))
        return;
    ICommand[] newCommands;
    if (status) {
        newCommands = new ICommand[commands.length + 1];
        System.arraycopy(commands, 0, newCommands, 0, commands.length);
        ICommand command = description.newCommand();
        command.setBuilderName(builderName);
        newCommands[commands.length] = command;
    } else {
        newCommands = new ICommand[commands.length - 1];
        System.arraycopy(commands, 0, newCommands, 0, i);
        System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
    }
    description.setBuildSpec(newCommands);
    project.setDescription(description, null);
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Aggregations

IProjectDescription (org.eclipse.core.resources.IProjectDescription)36 IProject (org.eclipse.core.resources.IProject)17 CoreException (org.eclipse.core.runtime.CoreException)10 IWorkspace (org.eclipse.core.resources.IWorkspace)8 ICommand (org.eclipse.core.resources.ICommand)7 IPath (org.eclipse.core.runtime.IPath)6 IStatus (org.eclipse.core.runtime.IStatus)6 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)5 HashSet (java.util.HashSet)4 IResource (org.eclipse.core.resources.IResource)4 Status (org.eclipse.core.runtime.Status)4 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 URI (java.net.URI)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 Project (org.talend.core.model.general.Project)3 User (org.talend.core.model.properties.User)3 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)3