Skip to content

Commit

Permalink
#212 Make commandline coherent with the Capella one
Browse files Browse the repository at this point in the history
Update command lines to inherit from DefaultCommandLine instead of
AbstractCommandLine.
Use 'input' parameter instead of 'filepath' for input model workspace
path.

Change-Id: I0000000000000000000000000000000000000000
Signed-off-by: Arnaud Dieumegard <arnaud.dieumegard@obeo.fr>
  • Loading branch information
arnauddieumegard authored and pdulth committed Mar 23, 2023
1 parent b728e4d commit 5406a16
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 76 deletions.
Expand Up @@ -12,6 +12,9 @@

package org.polarsys.capella.docgen.commandline;

import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -36,8 +39,9 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.polarsys.capella.core.commandline.core.AbstractCommandLine;
import org.polarsys.capella.common.helpers.EcoreUtil2;
import org.polarsys.capella.core.commandline.core.CommandLineException;
import org.polarsys.capella.core.commandline.core.DefaultCommandLine;
import org.polarsys.capella.core.data.capellamodeller.Project;
import org.polarsys.capella.core.sirius.ui.helper.SessionHelper;
import org.polarsys.kitalpha.doc.gen.business.core.sirius.util.session.DiagramSessionHelper;
Expand All @@ -46,7 +50,7 @@
/**
*
*/
public class HTMLCommandLine extends AbstractCommandLine {
public class HTMLCommandLine extends DefaultCommandLine {

private static final String FCORE_URI = "/org.polarsys.capella.docgen.ui/egf/capellalauncher.fcore#_zup7kAkdEeCBJtEcjZDVOA"; //$NON-NLS-1$
private static final URI CAPELLA_LAUNCHER_URI = URI.createURI("platform:/plugin" + FCORE_URI); //$NON-NLS-1$
Expand All @@ -60,7 +64,7 @@ public HTMLCommandLine() {

@Override
public void printHelp() {
System.out.println("Capella HTML Command Line"); //$NON-NLS-1$
System.out.println("*** Capella HTML Command Line"); //$NON-NLS-1$
super.printHelp();
}

Expand All @@ -81,39 +85,48 @@ public boolean execute(IApplicationContext context_p) {
startFakeWorkbench();

// load the AIRD
String fileURI = Messages.resource_prefix + argHelper.getFilePath();
URI uri = URI.createURI(fileURI);

// init the EGF activity
Activity htmlGenerator = InvokeActivityHelper.getActivity(CAPELLA_LAUNCHER_URI);

URI semanticResourceURI = uri;

if (uri.lastSegment().endsWith(".aird")) {//$NON-NLS-1$

DiagramSessionHelper.setAirdUri(uri);
Session session = DiagramSessionHelper.initSession();

session.open(new NullProgressMonitor());

Project rootSemanticElement = SessionHelper.getCapellaProject(session);
if (rootSemanticElement != null) {
Resource semanticResource = rootSemanticElement.eResource();
semanticResourceURI = semanticResource.getURI();

boolean status = executeEGFActivity(htmlGenerator, argHelper.getOutputFolder(), semanticResourceURI);

if (status) {
logInfo(Messages.generation_done + argHelper.getOutputFolder());
}
} else {
logError(Messages.no_root_semantic_element);
}
} else {
logError(Messages.filepath_point_to_aird);
List<IFile> airdFilesFromInput = getAirdFilesFromInput();
boolean status = true;
if (!airdFilesFromInput.isEmpty()) {
URI uri = EcoreUtil2.getURI(airdFilesFromInput.get(0));
// init the EGF activity
Activity htmlGenerator = InvokeActivityHelper.getActivity(CAPELLA_LAUNCHER_URI);

URI semanticResourceURI = uri;

if (uri.lastSegment().endsWith(".aird")) {//$NON-NLS-1$

DiagramSessionHelper.setAirdUri(uri);
Session session = DiagramSessionHelper.initSession();

session.open(new NullProgressMonitor());

Project rootSemanticElement = SessionHelper.getCapellaProject(session);
if (rootSemanticElement != null) {
Resource semanticResource = rootSemanticElement.eResource();
semanticResourceURI = semanticResource.getURI();

try {
String outputFolderString = getOrCreateOutputFolder().getFullPath().toString();
status = executeEGFActivity(htmlGenerator, outputFolderString, semanticResourceURI);
if (status) {
logInfo(Messages.generation_done + outputFolderString);
}
} catch (CommandLineException e) {
status = false;
logError(e.getMessage());
}
} else {
status = false;
logError(Messages.no_root_semantic_element);
}
} else {
status = false;
logError(Messages.filepath_point_to_aird);
}
}

return true;
return status;
}

/**
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.Collection;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -42,9 +43,10 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.polarsys.capella.core.commandline.core.AbstractCommandLine;
import org.polarsys.capella.common.helpers.EcoreUtil2;
import org.polarsys.capella.core.commandline.core.CommandLineArgumentHelper;
import org.polarsys.capella.core.commandline.core.CommandLineException;
import org.polarsys.capella.core.commandline.core.DefaultCommandLine;
import org.polarsys.capella.core.data.capellamodeller.Project;
import org.polarsys.capella.core.sirius.ui.helper.SessionHelper;
import org.polarsys.capella.docgen.configuration.ui.utils.ConfigurationUtils;
Expand All @@ -60,7 +62,7 @@
* org.polarsys.capella.docgen.commandline.HTMLCommandLine. Update execute
* method to launch generation on configuration file elements.
*/
public class HTMLConfigurationCommandLine extends AbstractCommandLine {
public class HTMLConfigurationCommandLine extends DefaultCommandLine {

private static final String FCORE_URI = "/org.polarsys.capella.docgen.ui/egf/capellalauncher.fcore#_zup7kAkdEeCBJtEcjZDVOA";
private static final URI CAPELLA_LAUNCHER_URI = URI.createURI("platform:/plugin" + FCORE_URI); //$NON-NLS-1$
Expand All @@ -85,8 +87,9 @@ public HTMLConfigurationCommandLine() {
*/
@Override
public void printHelp() {
System.out.println("Capella HTML with Configuration Command Line"); //$NON-NLS-1$
System.out.println("*** Capella HTML with Configuration Command Line"); //$NON-NLS-1$
super.printHelp();
System.out.println("-configurationFile value : defines the path to the configuration file");
}

/**
Expand Down Expand Up @@ -123,45 +126,51 @@ public boolean execute(IApplicationContext context_p) {
startFakeWorkbench();

// load the AIRD
String fileURI = Messages.resource_prefix + argHelper.getFilePath();
URI uri = URI.createURI(fileURI);

URI semanticResourceURI = uri;
boolean status = true;

if (uri.lastSegment().endsWith(".aird")) {//$NON-NLS-1$

DiagramSessionHelper.setAirdUri(uri);
Session session = DiagramSessionHelper.initSession();

session.open(new NullProgressMonitor());
// initialize scope
boolean init = initializeScope(session);
if (!init) {
return true;
}

// init the EGF activity
Activity htmlGenerator = InvokeActivityHelper.getActivity(CAPELLA_LAUNCHER_URI);

Project rootSemanticElement = SessionHelper.getCapellaProject(session);
if (rootSemanticElement != null) {
Resource semanticResource = rootSemanticElement.eResource();
semanticResourceURI = semanticResource.getURI();

status = executeEGFActivity(htmlGenerator, argHelper.getOutputFolder(), semanticResourceURI);

if (status) {
logInfo(Messages.generation_done + argHelper.getOutputFolder());
}
} else {
status = false;
logError(Messages.no_root_semantic_element);
}
} else {
status = false;
logError(Messages.filepath_point_to_aird);
}
List<IFile> airdFilesFromInput = getAirdFilesFromInput();
boolean status = true;
if (!airdFilesFromInput.isEmpty()) {
URI uri = EcoreUtil2.getURI(airdFilesFromInput.get(0));
URI semanticResourceURI = uri;

if (uri.lastSegment().endsWith(".aird")) {//$NON-NLS-1$

DiagramSessionHelper.setAirdUri(uri);
Session session = DiagramSessionHelper.initSession();

session.open(new NullProgressMonitor());
// initialize scope
boolean init = initializeScope(session);
if (!init) {
return true;
}

// init the EGF activity
Activity htmlGenerator = InvokeActivityHelper.getActivity(CAPELLA_LAUNCHER_URI);

Project rootSemanticElement = SessionHelper.getCapellaProject(session);
if (rootSemanticElement != null) {
Resource semanticResource = rootSemanticElement.eResource();
semanticResourceURI = semanticResource.getURI();

try {
String outputFolderString = getOrCreateOutputFolder().getFullPath().toString();
status = executeEGFActivity(htmlGenerator, outputFolderString, semanticResourceURI);
if (status) {
logInfo(Messages.generation_done + outputFolderString);
}
} catch (CommandLineException e) {
status = false;
logError(e.getMessage());
}
} else {
status = false;
logError(Messages.no_root_semantic_element);
}
} else {
status = false;
logError(Messages.filepath_point_to_aird);
}
}

return status;
}
Expand Down

0 comments on commit 5406a16

Please sign in to comment.