Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Add cli support for Grafico #14

Open
wants to merge 3 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
7 changes: 7 additions & 0 deletions org.archicontribs.grafico.commandline/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions org.archicontribs.grafico.commandline/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
34 changes: 34 additions & 0 deletions org.archicontribs.grafico.commandline/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.archicontribs.grafico.commandline</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
22 changes: 22 additions & 0 deletions org.archicontribs.grafico.commandline/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2013-2018 Phillip Beauvoir, Jean-Baptiste Sarrodie

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
11 changes: 11 additions & 0 deletions org.archicontribs.grafico.commandline/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Grapfico Command Line
Bundle-SymbolicName: org.archicontribs.grafico.commandline;singleton:=true
Bundle-Localization: plugin
Bundle-Version: 4.2.0.qualifier
Bundle-Vendor: Phillip Beauvoir
Require-Bundle: org.archicontribs.grafico,
com.archimatetool.commandline
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 changes: 8 additions & 0 deletions org.archicontribs.grafico.commandline/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jars.compile.order = .
bin.includes = META-INF/,\
.,\
plugin.properties,\
LICENSE.txt,\
plugin.xml
source.. = src/
output.. = bin/
Empty file.
20 changes: 20 additions & 0 deletions org.archicontribs.grafico.commandline/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="com.archimatetool.commandline.commandlineProvider">
<commandlineProvider
class="org.archicontribs.grafico.commandline.ExportGraficoProvider"
description="Export the current model to a Grafico filder"
id="org.archicontribs.grafico.commandline.exportProvider"
name="Export to Grafico">
</commandlineProvider>
<commandlineProvider
class="org.archicontribs.grafico.commandline.ImportGraficoProvider"
description="Import a model from a Gafico folder"
id="org.archicontribs.grafico.commandline.importProvider"
name="Import from Grafico">
</commandlineProvider>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* This program and the accompanying materials
* are made available under the terms of the License
* which accompanies this distribution in the file LICENSE.txt
*/
package org.archicontribs.grafico.commandline;

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

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.eclipse.osgi.util.NLS;

import com.archimatetool.commandline.AbstractCommandLineProvider;
import com.archimatetool.commandline.CommandLineState;
import org.archicontribs.grafico.commandline.Messages;

import org.archicontribs.grafico.GraficoExporter;
import com.archimatetool.editor.utils.StringUtils;
import com.archimatetool.model.IArchimateModel;

/**
* Command Line interface for CSV Export
*
* Typical usage - (should be all on one line):
*
* Archi -consoleLog -nosplash -application com.archimatetool.commandline.app
--loadModel "/pathToModel/model.archimate"
--exportToCSV "/pathToOutputFolder"
*
* @author Phillip Beauvoir
*/
public class ExportGraficoProvider extends AbstractCommandLineProvider {

static final String PREFIX = Messages.ExportGraficoProvider_0;

static final String OPTION_EXPORT_GRAFICO = "grafico.export"; //$NON-NLS-1$

public ExportGraficoProvider() {
}


@Override
public void run(CommandLine commandLine) throws Exception {
if(!hasCorrectOptions(commandLine)) {
return;
}

IArchimateModel model = CommandLineState.getModel();

if(model == null) {
throw new IOException(Messages.ExportGraficoProvider_1);
}
GraficoExporter exporter = new GraficoExporter(model);

// Folder
String grafico_export_path = commandLine.getOptionValue(OPTION_EXPORT_GRAFICO);
if(!StringUtils.isSet(grafico_export_path)) {
logError(Messages.ExportGraficoProvider_2);
return;
}
File folderOutput = new File(grafico_export_path);
folderOutput.mkdirs();
if(!folderOutput.exists()) {
logError(NLS.bind(Messages.ExportGraficoProvider_3, grafico_export_path));
return;
}

exporter.export(folderOutput);
logMessage(Messages.ExportGraficoProvider_5);
}

@Override
protected String getLogPrefix() {
return PREFIX;
}

@Override
public Options getOptions() {
Options options = new Options();

Option option = Option.builder()
.longOpt(OPTION_EXPORT_GRAFICO)
.hasArg().argName(Messages.ExportGraficoProvider_6)
.desc(Messages.ExportGraficoProvider_7)
.build();
options.addOption(option);

return options;
}

private boolean hasCorrectOptions(CommandLine commandLine) {
return commandLine.hasOption(OPTION_EXPORT_GRAFICO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* This program and the accompanying materials
* are made available under the terms of the License
* which accompanies this distribution in the file LICENSE.txt
*/
package org.archicontribs.grafico.commandline;

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

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.eclipse.osgi.util.NLS;

import com.archimatetool.commandline.AbstractCommandLineProvider;
import com.archimatetool.commandline.CommandLineState;
import org.archicontribs.grafico.GraficoImporter;
import com.archimatetool.editor.utils.StringUtils;
import com.archimatetool.model.IArchimateModel;

/**
* Command Line interface for CSV Import
*
* Typical usage - (should be all on one line):
*
* Archi -consoleLog -nosplash -application com.archimatetool.commandline.app
--createEmptyModel
--importFromCSV "/elements.csv"
*
* @author Phillip Beauvoir
*/
public class ImportGraficoProvider extends AbstractCommandLineProvider {

static final String PREFIX = Messages.ImportGraficoProvider_0;

static final String OPTION_IMPORT_GRAFICO = "grafico.import"; //$NON-NLS-1$

public ImportGraficoProvider() {
}


@Override
public void run(CommandLine commandLine) throws Exception {
if(!hasCorrectOptions(commandLine)) {
return;
}

IArchimateModel model = CommandLineState.getModel();

if(model == null) {
throw new IOException(Messages.ImportGraficoProvider_1);
}

// Folder
String value = commandLine.getOptionValue(OPTION_IMPORT_GRAFICO);
if(!StringUtils.isSet(value)) {
logError(Messages.ImportGraficoProvider_2);
return;
}
File elementsFile = new File(value);
if(!elementsFile.exists()) {
logError(NLS.bind(Messages.ImportGraficoProvider_3, value));
return;
}

//logMessage(NLS.bind(Messages.ImportGraficoProvider_4, elementsFile.getPath(), model.getName()));

GraficoImporter importer = new GraficoImporter(model);
model = importer.doImport(elementsFile);
CommandLineState.setModel(model);

logMessage(Messages.ImportGraficoProvider_5);
}

@Override
protected String getLogPrefix() {
return PREFIX;
}

public int getPriority() {
return PRIORITY_IMPORT;
}

@Override
public Options getOptions() {
Options options = new Options();

Option option = Option.builder()
.longOpt(OPTION_IMPORT_GRAFICO)
.hasArg().argName(Messages.ImportGraficoProvider_6)
.desc(Messages.ImportGraficoProvider_7)
.build();
options.addOption(option);

return options;
}

private boolean hasCorrectOptions(CommandLine commandLine) {
return commandLine.hasOption(OPTION_IMPORT_GRAFICO);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.archicontribs.grafico.commandline;

import org.eclipse.osgi.util.NLS;

public class Messages extends NLS {

private static final String BUNDLE_NAME = "org.archicontribs.grafico.commandline.messages"; //$NON-NLS-1$

public static String ExportGraficoProvider_0;

public static String ExportGraficoProvider_1;

public static String ExportGraficoProvider_10;

public static String ExportGraficoProvider_11;

public static String ExportGraficoProvider_12;

public static String ExportGraficoProvider_13;

public static String ExportGraficoProvider_14;

public static String ExportGraficoProvider_15;

public static String ExportGraficoProvider_2;

public static String ExportGraficoProvider_3;

public static String ExportGraficoProvider_4;

public static String ExportGraficoProvider_5;

public static String ExportGraficoProvider_6;

public static String ExportGraficoProvider_7;

public static String ExportGraficoProvider_8;

public static String ExportGraficoProvider_9;

public static String ImportGraficoProvider_0;

public static String ImportGraficoProvider_1;

public static String ImportGraficoProvider_2;

public static String ImportGraficoProvider_3;

public static String ImportGraficoProvider_4;

public static String ImportGraficoProvider_5;

public static String ImportGraficoProvider_6;

public static String ImportGraficoProvider_7;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
}
}
Loading