use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class UndoLastCommitAction method run.
@Override
public void run() {
// Offer to save the model if open and dirty
// We need to do this to keep grafico and temp files in sync
IArchimateModel model = getRepository().locateModel();
if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
if (!offerToSaveModel(model)) {
return;
}
}
boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.UndoLastCommitAction_0, Messages.UndoLastCommitAction_1);
if (!response) {
return;
}
try {
// Do it!
// $NON-NLS-1$
getRepository().resetToRef("HEAD^");
// Reload the model from the Grafico XML files
new GraficoModelLoader(getRepository()).loadModel();
// Save the checksum
getRepository().saveChecksum();
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.UndoLastCommitAction_0, ex);
}
notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
}
use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelLoader method restoreProblemObjects.
/**
* Find the problem object xml files from the commit history and restore them
* @param unresolvedObjects
* @return
* @throws IOException
*/
private IArchimateModel restoreProblemObjects(List<UnresolvedObject> unresolvedObjects) throws IOException {
fRestoredObjects = new ArrayList<IIdentifier>();
List<String> restoredIdentifiers = new ArrayList<String>();
try (Repository repository = Git.open(fRepository.getLocalRepositoryFolder()).getRepository()) {
try (RevWalk revWalk = new RevWalk(repository)) {
for (UnresolvedObject unresolved : unresolvedObjects) {
String missingFileName = unresolved.missingObjectURI.lastSegment();
String missingObjectID = unresolved.missingObjectURI.fragment();
// Already got this one
if (restoredIdentifiers.contains(missingObjectID)) {
continue;
}
boolean found = false;
// Reset RevWalk
revWalk.reset();
ObjectId id = repository.resolve(IGraficoConstants.REFS_HEADS_MASTER);
if (id != null) {
revWalk.markStart(revWalk.parseCommit(id));
}
// Iterate all commits
for (RevCommit commit : revWalk) {
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
// We can't use a PathFilter for the file name as its path is not correct
while (!found && treeWalk.next()) {
// File is found
if (treeWalk.getPathString().endsWith(missingFileName)) {
// Save file
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
File file = new File(fRepository.getLocalRepositoryFolder(), treeWalk.getPathString());
file.getParentFile().mkdirs();
GraficoUtils.writeObjectToFileWithSystemLineEndings(file, loader);
restoredIdentifiers.add(missingObjectID);
found = true;
}
}
}
if (found) {
break;
}
}
}
revWalk.dispose();
}
}
// Then re-import
GraficoModelImporter importer = new GraficoModelImporter(fRepository.getLocalRepositoryFolder());
IArchimateModel graficoModel = importer.importAsModel();
// do this again
graficoModel.setFile(fRepository.getTempModelFile());
// Collect restored objects
for (Iterator<EObject> iter = graficoModel.eAllContents(); iter.hasNext(); ) {
EObject element = iter.next();
for (String id : restoredIdentifiers) {
if (element instanceof IIdentifier && id.equals(((IIdentifier) element).getId())) {
fRestoredObjects.add((IIdentifier) element);
}
}
}
return graficoModel;
}
use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class ResetToRemoteCommitAction method run.
@Override
public void run() {
// Offer to save the model if open and dirty
// We need to do this to keep grafico and temp files in sync
IArchimateModel model = getRepository().locateModel();
if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
if (!offerToSaveModel(model)) {
return;
}
}
// Do the Grafico Export first
try {
getRepository().exportModelToGraficoFiles();
} catch (IOException ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
return;
}
try {
// If there are changes to commit then they'll have to be committed first or abandoned
if (getRepository().hasChangesToCommit()) {
if (!MessageDialog.openConfirm(fWindow.getShell(), Messages.ResetToRemoteCommitAction_0, Messages.ResetToRemoteCommitAction_2)) {
return;
}
} else // Else, confirm
{
boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.ResetToRemoteCommitAction_0, Messages.ResetToRemoteCommitAction_3);
if (!response) {
return;
}
}
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_4, ex);
return;
}
// Do it!
try {
getRepository().resetToRef(IGraficoConstants.ORIGIN_MASTER);
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
}
// Reload the model from the Grafico XML files
try {
new GraficoModelLoader(getRepository()).loadModel();
// Save the checksum
getRepository().saveChecksum();
} catch (IOException ex) {
displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
}
notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
}
use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class ArchiRepositoryTests method locateModel_LocateNewModel.
@Test
public void locateModel_LocateNewModel() {
File localRepoFolder = new File("/temp/folder");
IArchiRepository repo = new ArchiRepository(localRepoFolder);
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setFile(repo.getTempModelFile());
// Not open
assertNull(repo.locateModel());
IEditorModelManager.INSTANCE.openModel(model);
assertEquals(model, repo.locateModel());
}
use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.
the class GraficoUtilsTests method getLocalGitFolderForModel_IsCorrect.
@Test
public void getLocalGitFolderForModel_IsCorrect() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
File expected = new File("parent/parent/");
File file = new File(expected, ".git/" + IGraficoConstants.LOCAL_ARCHI_FILENAME);
model.setFile(file);
assertEquals(expected, GraficoUtils.getLocalRepositoryFolderForModel(model));
}
Aggregations