| /******************************************************************************* |
| * Copyright (c) 2008-2011 Chair for Applied Software Engineering, |
| * Technische Universitaet Muenchen. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| ******************************************************************************/ |
| package org.eclipse.emf.emfstore.client.proxy.example; |
| |
| import java.util.Date; |
| |
| import org.eclipse.emf.emfstore.client.model.impl.ProjectSpaceImpl; |
| import org.eclipse.emf.emfstore.client.proxy.ProxyClient; |
| import org.eclipse.emf.emfstore.server.exceptions.EmfStoreException; |
| import org.eclipse.emf.emfstore.server.exceptions.InvalidVersionSpecException; |
| import org.eclipse.emf.emfstore.server.model.ProjectInfo; |
| import org.eclipse.emf.emfstore.server.model.versioning.ChangePackage; |
| import org.eclipse.emf.emfstore.server.model.versioning.PrimaryVersionSpec; |
| import org.eclipse.emf.emfstore.server.model.versioning.TagVersionSpec; |
| import org.eclipse.emf.emfstore.server.model.versioning.VersioningFactory; |
| import org.eclipse.emf.emfstore.server.model.versioning.Versions; |
| import org.eclipse.emf.emfstore.server.model.versioning.operations.AbstractOperation; |
| |
| /** |
| * Example client that fixes a comment. |
| * |
| */ |
| public class CommentFixClient extends ProxyClient { |
| |
| /** |
| * Runs the client. |
| */ |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void run() throws Exception { |
| |
| loginServer("super", "blub", "unicase.in.tum.de", "0.3.40", "unicase.org 2009#1", 443); |
| |
| // ProjectInfo projectInfo = getProjectInfo("unicase", false); |
| |
| for (ProjectInfo projectInfo : getConnectionManager().getProjectList(getSessionId())) { |
| fixProject(projectInfo); |
| } |
| } |
| |
| // END SUPRESS CATCH EXCEPTION |
| |
| private void fixProject(ProjectInfo projectInfo) throws EmfStoreException, InvalidVersionSpecException { |
| System.out.println("Checking project: " + projectInfo.getName()); |
| |
| ProjectSpaceImpl projectSpace = createTransientProjectSpace(getConnectionManager().getProject(getSessionId(), |
| projectInfo.getProjectId(), projectInfo.getVersion())); |
| |
| // for (ModelElement me : projectSpace.getProject().getAllModelElements()) { |
| // if (me instanceof UnicaseModelElement) { |
| // UnicaseModelElement modelElement = (UnicaseModelElement) me; |
| // if (modelElement instanceof Comment) { |
| // if (modelElement.getDescription() == null |
| // || modelElement.getDescription().equals("")) { |
| // String name = modelElement.getName(); |
| // if (name == null) { |
| // continue; |
| // } |
| // modelElement.setDescription(name); |
| // if (20 < (name.length())) { |
| // name = name.substring(0, 20) + "..."; |
| // } |
| // modelElement.setName(name); |
| // } |
| // } |
| // } |
| // } |
| |
| ChangePackage localChangePackage = projectSpace.getLocalChangePackage(true); |
| for (AbstractOperation ao : localChangePackage.getOperations()) { |
| System.out.println(ao); |
| } |
| |
| if (localChangePackage.getOperations().size() == 0) { |
| System.out.println("no changes..."); |
| return; |
| } |
| |
| // TODO: check whether version parameters are set correctly |
| PrimaryVersionSpec versionSpec = getConnectionManager().createVersion( |
| getSessionId(), |
| projectInfo.getProjectId(), |
| projectInfo.getVersion(), |
| localChangePackage, |
| Versions.createBRANCH(projectSpace.getBaseVersion().getBranch()), |
| getProjectSpace().getBaseVersion(), |
| createLogMessage("super", |
| "automatic commit: copied name from comment to description, if description was empty.", new Date())); |
| |
| System.out.println("new version: " + versionSpec.getIdentifier()); |
| |
| getConnectionManager() |
| .addTag(getSessionId(), projectInfo.getProjectId(), versionSpec, createTag("Comment fix")); |
| } |
| |
| private TagVersionSpec createTag(String string) { |
| TagVersionSpec tagVersionSpec = VersioningFactory.eINSTANCE.createTagVersionSpec(); |
| tagVersionSpec.setName(string); |
| return tagVersionSpec; |
| } |
| } |