Skip to content
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
32 changes: 24 additions & 8 deletions org.archicontribs.modelrepository.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,39 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
</license>

<includes
id="org.eclipse.tm.terminal.connector.local.feature"
version="0.0.0"
os="linux,macosx,win32"/>

<includes
id="org.eclipse.tm.terminal.control.feature"
version="0.0.0"/>

<includes
id="org.eclipse.tm.terminal.feature"
version="0.0.0"/>

<includes
id="org.eclipse.tm.terminal.view.feature"
version="0.0.0"/>

<requires>
<import plugin="org.eclipse.help.ui"/>
<import plugin="com.archimatetool.editor"/>
</requires>

<plugin
id="org.archicontribs.modelrepository"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
version="0.0.0"/>

<plugin
id="org.archicontribs.modelrepository.commandline"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
version="0.0.0"/>

<plugin
id="org.eclipse.cdt.core.native"
os="linux,macosx,win32"
version="0.0.0"/>

</feature>
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>
2 changes: 1 addition & 1 deletion org.archicontribs.modelrepository/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Bundle-Vendor: Archi
Require-Bundle: org.eclipse.help.ui,
com.archimatetool.editor;bundle-version="4.9.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 @@ -380,7 +380,8 @@ public void run(IProgressMonitor pm) {
try {
// Export
GraficoModelExporter exporter = new GraficoModelExporter(model, getLocalRepositoryFolder());
exporter.exportModel();
//exporter.exportModel();
exporter.exportChangedModel();

// Check lock file is deleted
checkDeleteLockFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public GraficoModelExporter(IArchimateModel model, File folder) {
fModel = model;
fLocalRepoFolder = folder;
}


public void exportChangedModel() {
File modelFolder = new File(fLocalRepoFolder, IGraficoConstants.MODEL_FOLDER);


// additive



// subtractive

}

/**
* Export the IArchimateModel as Grafico files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.archicontribs.modelrepository.grafico;

import java.io.File;
import java.io.IOException;

import org.archicontribs.modelrepository.authentication.UsernamePassword;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;

import com.archimatetool.editor.actions.AbstractModelAction;

import de.esserjan.edu.imbecile.GitExecutionException;
import de.esserjan.edu.imbecile.GitExecutionResult;
import de.esserjan.edu.imbecile.GitExecutor;
import de.esserjan.edu.imbecile.GitExecutor.PullMode;

/**
* ShellArchiRepository challenges ArchiRepository with alternative GIT
* back-end.
*
* Hexagonal force field: driven by: descendants of {@link AbstractModelAction},
* driver: git-executor
*/
public class ShellArchiRepository {

public static enum PullOutcome {
ALREADY_UP_TO_DATE, PULLED_SUCCESSFULLY, PULL_INCOMPLETE
}

private GitExecutor executor;

public ShellArchiRepository() {
// inject manually as this isn't managed instance
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
this.executor = bundleContext.getService(bundleContext.getServiceReference(GitExecutor.class));
this.executor.setGitExecutable(new File("/snap/eclipse-pde/current/usr/bin/git"));
}

public void setLocalRepoFolder(File localRepoFolder) {
this.executor.setGitRepo(localRepoFolder);
}

public PullOutcome pullFromRemote(UsernamePassword npw) throws IOException {
try {
GitExecutionResult result = executor.pull(PullMode.REBASE_MERGE);
switch (result.exitCode()) {
case 0:
if (result.outputText().endsWith("."))
return PullOutcome.ALREADY_UP_TO_DATE;
else
return PullOutcome.PULLED_SUCCESSFULLY;
default:
return PullOutcome.PULL_INCOMPLETE;
}
} catch (GitExecutionException e) {
throw new IOException(e);
}
}

public boolean hasChanges() throws IOException {
try {
return executor.hasChanges();
} catch (GitExecutionException e) {
throw new IOException(e);
}
}

public boolean commit(String commitMessage, boolean amend) throws IOException {
try {
return 0 == executor.commit(commitMessage, amend, false, true).exitCode();
} catch (GitExecutionException e) {
throw new IOException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class ModelRepositoryView
public void createPartControl(Composite parent) {
// Create the Tree Viewer first
fTreeViewer = new ModelRepositoryTreeViewer(parent);


makeActions();
registerGlobalActions();
Expand Down