Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archi-modelrepository-plugin object-history #221

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion org.archicontribs.modelrepository/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<classpathentry exported="true" kind="lib" path="lib/org.eclipse.jgit_6.1.0.202203080745-r.jar" sourcepath="libsrc/org.eclipse.jgit.source_6.1.0.202203080745-r.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org.eclipse.jgit.ssh.apache_6.1.0.202203080745-r.jar" sourcepath="libsrc/org.eclipse.jgit.ssh.apache.source_6.1.0.202203080745-r.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org.apache.sshd.osgi_2.8.0.v20211227-1750.jar" sourcepath="libsrc/org.apache.sshd.osgi.source_2.8.0.v20211227-1750.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/javaewah_1.1.13.v20211029-0839.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org.slf4j.api_1.7.30.v20200204-2150.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org.slf4j.binding.simple_1.7.30.v20200204-2150.jar"/>
<classpathentry exported="true" kind="lib" path="lib/net.i2p.crypto.eddsa_0.3.0.v20210923-1401.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
7 changes: 4 additions & 3 deletions org.archicontribs.modelrepository/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Bundle-ManifestVersion: 2
Bundle-Name: coArchi
Bundle-SymbolicName: org.archicontribs.modelrepository;singleton:=true
Bundle-Localization: plugin
Bundle-Version: 0.9.2.qualifier
Bundle-Version: 0.9.3.qualifier
Bundle-Vendor: Archi
Require-Bundle: org.eclipse.help.ui,
com.archimatetool.editor;bundle-version="4.9.0"
com.archimatetool.editor;bundle-version="4.9.0",
git-executor;bundle-version="1.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Bundle-Activator: org.archicontribs.modelrepository.ModelRepositoryPlugin
Export-Package: org.archicontribs.modelrepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.archicontribs.modelrepository.grafico.IArchiRepository;
import org.archicontribs.modelrepository.grafico.IRepositoryListener;
import org.archicontribs.modelrepository.grafico.RepositoryListenerManager;
import org.archicontribs.modelrepository.grafico.ShellArchiRepository;
import org.archicontribs.modelrepository.preferences.IPreferenceConstants;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
Expand All @@ -36,24 +37,41 @@ public abstract class AbstractModelAction extends Action implements IGraficoMode

private IArchiRepository fRepository;

private ShellArchiRepository shellRepository;

protected IWorkbenchWindow fWindow;

protected AbstractModelAction(IWorkbenchWindow window) {
fWindow = window;

this.shellRepository = new ShellArchiRepository();
}

@Override
public void setRepository(IArchiRepository repository) {
fRepository = repository;
setEnabled(shouldBeEnabled());
getShellRepository().setLocalRepoFolder(repository.getLocalRepositoryFolder());
}

@Override
public IArchiRepository getRepository() {
return fRepository;
}

public boolean isShellModeAvailable() {
return this.shellRepository != null;
}

@Override
public void setShellRepository(ShellArchiRepository shellRepository) {
this.shellRepository = shellRepository;
}

public ShellArchiRepository getShellRepository() {
return shellRepository;
}

@Override
public void update() {
setEnabled(shouldBeEnabled());
}
Expand Down Expand Up @@ -124,8 +142,12 @@ protected boolean offerToCommitChanges() {
boolean amend = commitDialog.getAmend();

try {
getRepository().commitChanges(commitMessage, amend);

if (isShellModeAvailable()) {
getShellRepository().commit(commitMessage, amend);
} else {
getRepository().commitChanges(commitMessage, amend);

}
// Save the checksum
getRepository().saveChecksum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.GeneralSecurityException;
import java.util.logging.Logger;

import org.archicontribs.modelrepository.IModelRepositoryImages;
import org.archicontribs.modelrepository.authentication.ProxyAuthenticator;
Expand All @@ -18,6 +19,7 @@
import org.archicontribs.modelrepository.grafico.GraficoModelLoader;
import org.archicontribs.modelrepository.grafico.GraficoUtils;
import org.archicontribs.modelrepository.grafico.IRepositoryListener;
import org.archicontribs.modelrepository.grafico.ShellArchiRepository.PullOutcome;
import org.archicontribs.modelrepository.merge.MergeConflictHandler;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
Expand Down Expand Up @@ -51,26 +53,29 @@
* @author Phillip Beauvoir
*/
public class RefreshModelAction extends AbstractModelAction {
protected static final int PULL_STATUS_ERROR = -1;
protected static final int PULL_STATUS_OK = 0;
protected static final int PULL_STATUS_UP_TO_DATE = 1;
protected static final int PULL_STATUS_MERGE_CANCEL = 2;

protected static final int USER_OK = 0;
protected static final int USER_CANCEL = 1;

private static final Logger LOGGER = Logger.getLogger(RefreshModelAction.class.getName());

public RefreshModelAction(IWorkbenchWindow window) {
super(window);
setImageDescriptor(IModelRepositoryImages.ImageFactory.getImageDescriptor(IModelRepositoryImages.ICON_REFRESH));
setText(Messages.RefreshModelAction_0);
setToolTipText(Messages.RefreshModelAction_0);
}

public RefreshModelAction(IWorkbenchWindow window, IArchimateModel model) {
this(window);

if(model != null) {
setRepository(new ArchiRepository(GraficoUtils.getLocalRepositoryFolderForModel(model)));
setRepository(new ArchiRepository(GraficoUtils.getLocalRepositoryFolderForModel(model)));
}
}

Expand Down Expand Up @@ -169,7 +174,8 @@ protected int init() throws IOException, GitAPIException {
getRepository().exportModelToGraficoFiles();

// Then offer to Commit
if(getRepository().hasChangesToCommit()) {
if((super.isShellModeAvailable() && super.getShellRepository().hasChanges())
|| getRepository().hasChangesToCommit()) {
if(!offerToCommitChanges()) {
return USER_CANCEL;
}
Expand All @@ -186,7 +192,21 @@ protected int pull(UsernamePassword npw, ProgressMonitorDialog pmDialog) throws
Display.getCurrent().readAndDispatch(); // update dialog

try {
pullResult = getRepository().pullFromRemote(npw, new ProgressMonitorWrapper(pmDialog.getProgressMonitor()));
if (super.isShellModeAvailable()) {
PullOutcome pullOutcome = super.getShellRepository().pullFromRemote(npw);
switch(pullOutcome) {
case ALREADY_UP_TO_DATE:
return PULL_STATUS_UP_TO_DATE;
case PULLED_SUCCESSFULLY:
// places loaded in model in IEditorModelManager
new GraficoModelLoader(getRepository()).loadModel();
return PULL_STATUS_OK;
case PULL_INCOMPLETE:
LOGGER.warning("Shell mode run into trouble, falling back to jgit handlings.");
}
}

pullResult = getRepository().pullFromRemote(npw, new ProgressMonitorWrapper(pmDialog.getProgressMonitor()));
}
catch(Exception ex) {
// If this exception is thrown then the remote doesn't have the ref which can happen when pulling on a branch,
Expand Down Expand Up @@ -289,7 +309,6 @@ protected int pull(UsernamePassword npw, ProgressMonitorDialog pmDialog) throws
commitMessage += "\n\n" + Messages.RefreshModelAction_3 + "\n" + restoredObjects; //$NON-NLS-1$ //$NON-NLS-2$
}

// TODO - not sure if amend should be false or true here?
getRepository().commitChanges(commitMessage, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class RestoreCommitAction extends AbstractModelAction {

public RestoreCommitAction(IWorkbenchWindow window) {
super(window);
setImageDescriptor(IModelRepositoryImages.ImageFactory.getImageDescriptor(IModelRepositoryImages.ICON_SYNCED));
setImageDescriptor(IModelRepositoryImages.ImageFactory.getImageDescriptor(IModelRepositoryImages.ICON_RESET));
setText(Messages.RestoreCommitAction_0);
setToolTipText(Messages.RestoreCommitAction_0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -170,12 +171,12 @@ private static Proxy createHTTPProxyFromPreferences() {
/**
* Test a http connection
*/
public static boolean testHTTPConnection(String url) throws IOException {
public static boolean testHTTPConnection(String url) throws IOException, URISyntaxException {
if(GraficoUtils.isSSH(url)) {
return false;
}

URL testURL = new URL(url);
URL testURL = new URI(url).toURL();

// localhost https connections throw certificate exceptions
if("localhost".equals(testURL.getHost()) || "127.0.0.1".equals(testURL.getHost())) { //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.swt.widgets.Text;

import com.archimatetool.editor.ui.IArchiImages;
import com.archimatetool.editor.ui.UIUtils;

/**
* Add Branch Dialog
Expand Down Expand Up @@ -98,7 +99,7 @@ private Text createTextField(Composite container, String message, int style) {
Label label = new Label(container, SWT.NONE);
label.setText(message);

Text txt = new Text(container, SWT.BORDER | style);
Text txt = UIUtils.createSingleTextControl(container, SWT.BORDER | style, false);
txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

return txt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.swt.widgets.Text;

import com.archimatetool.editor.ui.IArchiImages;
import com.archimatetool.editor.ui.UIUtils;

/**
* Clone Input Dialog
Expand Down Expand Up @@ -89,7 +90,7 @@ protected Text createTextField(Composite container, String message, int style) {
Label label = new Label(container, SWT.NONE);
label.setText(message);

Text txt = new Text(container, SWT.BORDER | style);
Text txt = UIUtils.createSingleTextControl(container, SWT.BORDER | style, false);
txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

return txt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.swt.widgets.Text;

import com.archimatetool.editor.ui.IArchiImages;
import com.archimatetool.editor.ui.UIUtils;

/**
* User Name and Password Dialog
Expand Down Expand Up @@ -77,7 +78,7 @@ private Text createTextField(Composite container, String message, int style) {
Label label = new Label(container, SWT.NONE);
label.setText(message);

Text txt = new Text(container, SWT.BORDER | style);
Text txt = UIUtils.createSingleTextControl(container, SWT.BORDER | style, false);
txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

return txt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.archicontribs.modelrepository.grafico;

import java.io.File;

import org.eclipse.emf.ecore.EObject;

import com.archimatetool.model.FolderType;
import com.archimatetool.model.IFolder;
import com.archimatetool.model.IIdentifier;

public final class GraficoFileConventions {

private GraficoFileConventions() {
// utility class
}

public static File forFolder(File parentFolder, IFolder iFolder) {
return new File(parentFolder, GraficoFileConventions.getNameFor(iFolder));
}

public static File forElement(File modelFolder, IFolder iFolder, EObject elem) {
File elemFolder = new File(modelFolder, GraficoFileConventions.getNameFor(iFolder));
return GraficoFileConventions.forElement(elemFolder, elem);
}

public static File forElement(File elemFolder, EObject elem) {
return new File(elemFolder, elem.getClass().getSimpleName() + "_" + ((IIdentifier) elem).getId() + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
}

/**
* Generate a proper name for directory creation
*
* @param folder
* @return
*/
public static String getNameFor(IFolder folder) {
return folder.getType() == FolderType.USER ? folder.getId().toString() : folder.getType().toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@

import com.archimatetool.editor.model.IArchiveManager;
import com.archimatetool.editor.utils.FileUtils;
import com.archimatetool.model.FolderType;
import com.archimatetool.model.IArchimateModel;
import com.archimatetool.model.IDiagramModelImageProvider;
import com.archimatetool.model.IFolder;
import com.archimatetool.model.IFolderContainer;
import com.archimatetool.model.IIdentifier;


/**
Expand Down Expand Up @@ -177,7 +175,7 @@ private void createAndSaveResourceForFolder(IFolderContainer folderContainer, Fi
allFolders.addAll(folderContainer.getFolders());

for(IFolder tmpFolder : allFolders) {
File tmpFolderFile = new File(folder, getNameFor(tmpFolder));
File tmpFolderFile = GraficoFileConventions.forFolder(folder, tmpFolder);
tmpFolderFile.mkdirs();
createAndSaveResource(new File(tmpFolderFile, IGraficoConstants.FOLDER_XML), tmpFolder);
createAndSaveResourceForFolder(tmpFolder, tmpFolderFile);
Expand All @@ -190,25 +188,15 @@ private void createAndSaveResourceForFolder(IFolderContainer folderContainer, Fi
allElements.addAll(((IFolder)folderContainer).getElements());
for(EObject tmpElement : allElements) {
createAndSaveResource(
new File(folder, tmpElement.getClass().getSimpleName() + "_" + ((IIdentifier)tmpElement).getId() + ".xml"), //$NON-NLS-1$ //$NON-NLS-2$
GraficoFileConventions.forElement(folder, tmpElement),
tmpElement);
}
}
if(folderContainer instanceof IArchimateModel) {
createAndSaveResource(new File(folder, IGraficoConstants.FOLDER_XML), folderContainer);
}
}

/**
* Generate a proper name for directory creation
*
* @param folder
* @return
*/
private String getNameFor(IFolder folder) {
return folder.getType() == FolderType.USER ? folder.getId().toString() : folder.getType().toString();
}


/**
* Save the model to Resource
*
Expand Down
Loading