Skip to content

Duplicate ware ds #1326

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

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions CMake.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ SET(OFBUILD_CUSTOM_CMAKE_VERSION "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.

SET(OPENFLUID_VERSION_MAJOR 2)
SET(OPENFLUID_VERSION_MINOR 2)
SET(OPENFLUID_VERSION_PATCH 0)
SET(OPENFLUID_VERSION_STATUS "") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
SET(OPENFLUID_VERSION_PATCH 1)
SET(OPENFLUID_VERSION_STATUS "alpha1") # example: SET(OPENFLUID_VERSION_STATUS "rc1")

SET(OPENFLUID_VERSION_FULL "${OPENFLUID_VERSION_MAJOR}.${OPENFLUID_VERSION_MINOR}.${OPENFLUID_VERSION_PATCH}")

Expand Down
9 changes: 9 additions & 0 deletions cmake/OpenFLUIDTestScript.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ FUNCTION(EXECUTE_COMMAND CMD)
ENDIF()
FILE(REMOVE_RECURSE ${TMPDIR})

ELSEIF(${CMD} STREQUAL "CHECK_FILE_CONTAINS")
FILE(READ ${TMPDIR}/${ARGV1} TMPTXT)
STRING(FIND "${TMPTXT}" "${ARGV2}" ISMATCH)
IF(${ISMATCH} EQUAL -1)
MESSAGE(FATAL_ERROR "CHECK_FILE_CONTAINS: file ${ARGV1} does not contain string ${ARGV2}")
ENDIF()

ELSEIF(${CMD} STREQUAL "CHECK_FILE_IDENTICAL")
# generates consistent eol between files (can be replaced by option ignore_eol in cmake 3.14)
CONFIGURE_FILE(${ARGV1}${ARGV3} ${ARGV1}${ARGV3}_UNIX_EOL NEWLINE_STYLE UNIX)
Expand Down Expand Up @@ -116,6 +123,7 @@ FUNCTION(PARSE_COMMANDS)
IF(${CMD_EXPECTED})
IF(${ELEM} STREQUAL "CHECK_FILE_EXIST" OR
${ELEM} STREQUAL "CHECK_FILE_EXIST_IN_ARCHIVE" OR
${ELEM} STREQUAL "CHECK_FILE_CONTAINS" OR
${ELEM} STREQUAL "CHECK_FILE_IDENTICAL" OR
${ELEM} STREQUAL "CHECK_DIRECTORY_EXIST" OR
${ELEM} STREQUAL "CHECK_DIRECTORY_NOT_EXISTING" OR
Expand All @@ -141,6 +149,7 @@ FUNCTION(PARSE_COMMANDS)
ELSE()
IF(${CURRENT_CMD} STREQUAL "COMPARE_FILES" OR
${CURRENT_CMD} STREQUAL "CHECK_FILE_EXIST_IN_ARCHIVE" OR
${CURRENT_CMD} STREQUAL "CHECK_FILE_CONTAINS" OR
${CURRENT_CMD} STREQUAL "COMPARE_DIRECTORIES" OR
${CURRENT_CMD} STREQUAL "COPY_FILE" OR
${CURRENT_CMD} STREQUAL "COPY_DIRECTORY")
Expand Down
57 changes: 57 additions & 0 deletions src/apps/openfluid-devstudio/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ QToolButton::menu-button:pressed, QToolButton::menu-button:hover {
mp_WidgetsCollection, SLOT(openPath(const QString&)));
connect(Explorer, SIGNAL(deleteWareAsked()),
this, SLOT(onDeleteWareRequested()));
connect(Explorer, SIGNAL(duplicateWareAsked()),
this, SLOT(onDuplicateWareRequested()));
connect(Explorer, SIGNAL(fileDeleted(const QString&)),
mp_WidgetsCollection, SLOT(closeEditor(const QString&)));
connect(Explorer, SIGNAL(folderDeleted(const QString&, const QString&, const bool)),
Expand Down Expand Up @@ -724,6 +726,61 @@ void MainWindow::updateSaveButtonsStatus(bool FileModified, bool FileOpen, bool
// =====================================================================


void MainWindow::onDuplicateWareRequested()
{
QWidget* CurrentWidget = ui->WaresTabWidget->currentWidget();
QString SelectedPath = "";

if (CurrentWidget == ui->SimPage)
{
SelectedPath = ui->SimExplorer->getCurrentPath();
}
else if (CurrentWidget == ui->ObsPage)
{
SelectedPath = ui->ObsExplorer->getCurrentPath();
}
else if (CurrentWidget == ui->ExtPage)
{
SelectedPath = ui->ExtExplorer->getCurrentPath();
}

if (SelectedPath != "")
{
const auto WareInfo = openfluid::waresdev::WareSrcEnquirer::getWareInfoFromPath(SelectedPath.toStdString());
QString WarePath =
QString::fromStdString(
WareInfo.AbsoluteWarePath);
if (WarePath != "")
{
// add dialog to know more information
bool OK;
QString NewWareName = QInputDialog::getText(this, "Ware name",
"Name of the new ware:",
QLineEdit::Normal,
QString::fromStdString(WareInfo.WareDirName+".duplicate"),
&OK);
// TOIMPL reuse here the filter checking if ware name OK (not existing + only accepted symbols)
if (OK && !NewWareName.isEmpty() && WareInfo.WareDirName != NewWareName.toStdString())
{

mp_WidgetsCollection->duplicateWare(WarePath, NewWareName);
QMessageBox::warning(QApplication::activeWindow(),
tr("Ware duplication warning"),
tr("If this ware is versioned, change now the remote repository "
"(using 'git remote set-url origin <newurl>'). "
"It is currently the same than original ware and would "
"generate conflict or data loss risk."),
QMessageBox::Close);
}
}
}
}


// =====================================================================
// =====================================================================


void MainWindow::onDeleteWareRequested()
{
QWidget* CurrentWidget = ui->WaresTabWidget->currentWidget();
Expand Down
2 changes: 2 additions & 0 deletions src/apps/openfluid-devstudio/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class OPENFLUID_API MainWindow: public openfluid::ui::common::AppMainWindow

void updateSaveButtonsStatus(bool FileModified, bool FileOpen, bool WareModified);

void onDuplicateWareRequested();

void onDeleteWareRequested();

void onCloseAllWaresRequested();
Expand Down
49 changes: 39 additions & 10 deletions src/apps/openfluid/WareTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <openfluid/waresdev/WareSrcHelpers.hpp>
#include <openfluid/utils/Process.hpp>
#include <openfluid/utils/CMakeProxy.hpp>
#include <openfluid/utils/GitProxy.hpp>
#include <openfluid/tools/Filesystem.hpp>
#include <openfluid/tools/FilesystemPath.hpp>
#include <openfluid/tools/StringHelpers.hpp>
Expand All @@ -64,16 +65,28 @@
#include "DefaultDocalyzeListener.hpp"


int WareTasks::processCreate() const
void WareTasks::postWareCreation(const std::string& WarePath) const
{
if (!m_Cmd.isOptionActive("id"))
if (m_Cmd.isOptionActive("set-remote"))
{
return error("missing ware ID");
if (!openfluid::utils::GitProxy::isAvailable() || openfluid::utils::GitProxy::setRemote(WarePath,
m_Cmd.getOptionValue("set-remote")) != 0)
{
openfluid::utils::log::warning("Ware creation", "set-remote failed");
}
}
}

if (!m_Cmd.isOptionActive("type"))

// =====================================================================
// =====================================================================


int WareTasks::processCreate() const
{
if (!m_Cmd.isOptionActive("id"))
{
return error("missing ware type");
return error("missing ware ID");
}

const auto ID = m_Cmd.getOptionValue("id");
Expand All @@ -83,8 +96,6 @@ int WareTasks::processCreate() const
return error("invalid ware ID");
}

const auto TypeStr = m_Cmd.getOptionValue("type");

const auto ParentPath = (m_Cmd.getOptionValue("parent-path").empty() ? openfluid::tools::Filesystem::currentPath() :
m_Cmd.getOptionValue("parent-path"));

Expand All @@ -96,13 +107,29 @@ int WareTasks::processCreate() const
Config.MainClassName = (m_Cmd.getOptionValue("main-class").empty() ? Config.MainClassName :
m_Cmd.getOptionValue("main-class"));

if (m_Cmd.isOptionActive("from"))
{
const std::string WarePath = openfluid::waresdev::WareSrcFactory::duplicateWare(ID, ParentPath,
m_Cmd.getOptionValue("from"),
m_Cmd.isOptionActive("accept-all"));
postWareCreation(WarePath);
return 0;
}

if (!m_Cmd.isOptionActive("type"))
{
return error("missing ware type");
}
const auto TypeStr = m_Cmd.getOptionValue("type");

if (TypeStr == "simulator")
{
openfluid::ware::SimulatorSignature Sign;
Sign.ID = ID;
try
{
openfluid::waresdev::WareSrcFactory::createSimulator(Sign,Config,ParentPath);
const std::string WarePath = openfluid::waresdev::WareSrcFactory::createSimulator(Sign,Config,ParentPath);
postWareCreation(WarePath);
return 0;
}
catch(const openfluid::base::FrameworkException& E)
Expand All @@ -116,7 +143,8 @@ int WareTasks::processCreate() const
Sign.ID = ID;
try
{
openfluid::waresdev::WareSrcFactory::createObserver(Sign,Config,ParentPath);
const std::string WarePath = openfluid::waresdev::WareSrcFactory::createObserver(Sign,Config,ParentPath);
postWareCreation(WarePath);
return 0;
}
catch(const openfluid::base::FrameworkException& E)
Expand Down Expand Up @@ -165,7 +193,8 @@ int WareTasks::processCreate() const

try
{
openfluid::waresdev::WareSrcFactory::createBuilderext(Sign,Config,ParentPath);
const std::string WarePath = openfluid::waresdev::WareSrcFactory::createBuilderext(Sign,Config,ParentPath);
postWareCreation(WarePath);
return 0;
}
catch(const openfluid::base::FrameworkException& E)
Expand Down
2 changes: 2 additions & 0 deletions src/apps/openfluid/WareTasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class WareTasks : public TasksBase
{
private:

void postWareCreation(const std::string& WarePath) const;

int processCreate() const;

int processConfigure() const;
Expand Down
5 changes: 4 additions & 1 deletion src/apps/openfluid/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ int main(int argc, char **argv)
{"id","i","ID of the ware sources to create (required)",true},
{"main-class","m","name to use for the main C++ class",true},
{"parent-path","p","parent path where to create the ware sources",true},
{"from", "", "ware to use as reference"},
{"with-paramsui","w","generate the C++ class of the parameterization UI "
"(simulators and observers only)"},
{"paramsui-class","u","name to use for the C++ class of the parameterization UI "
Expand All @@ -205,7 +206,9 @@ int main(int argc, char **argv)
{"bext-category","","category the Builder-Extension"
"(spatial|model|results|other, default is other)",true},
{"bext-mode","","mode of Builder-Extension (modal|modeless|workspace, default is modal)",
true}});
true},
{"accept-all", "a", "say yes to any question (useful during ware duplication)"},
{"set-remote", "", "define the URL of remote git repository"}});
Parser.addCommand(CreateWareCmd, &WareSection);

// ---
Expand Down
18 changes: 18 additions & 0 deletions src/apps/openfluid/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,24 @@ ENDIF()
###########################################################################


OPENFLUID_ADD_TEST(NAME cmdline-openfluid-CreateWareSimulatorFromExisting
COMMAND "${OFBUILD_DIST_BIN_DIR}/${OPENFLUID_CMD_APP}"
"create-ware" "--id=tests.cmdline.sim.ilar"
"-p" "${OFBUILD_TMP_DIR}/cmdline/create-ware/sim"
"--from=${OFBUILD_TESTS_OUTPUT_DATA_DIR}/cmdline/create-ware/sim/tests.cmdline.sim"
"--set-remote=https://hub.foo.org/git-service/wares/simulators/tests.cmdline.sim.ilar"
"-a"
PRE_TEST REMOVE_DIRECTORY "${OFBUILD_TMP_DIR}/cmdline/create-ware/sim/tests.cmdline.sim.ilar"
POST_TEST CHECK_FILE_EXIST "${OFBUILD_TMP_DIR}/cmdline/create-ware/sim/tests.cmdline.sim.ilar/CMakeLists.txt"
POST_TEST CHECK_FILE_CONTAINS "${OFBUILD_TMP_DIR}/cmdline/create-ware/sim/tests.cmdline.sim.ilar/openfluid-ware.json" "tests.cmdline.sim.ilar"
POST_TEST CHECK_FILE_CONTAINS "${OFBUILD_TMP_DIR}/cmdline/create-ware/sim/tests.cmdline.sim.ilar/.git/config" "hub.foo.org")

SET_PROPERTY(TEST cmdline-openfluid-CreateWareSimulatorFromExisting APPEND PROPERTY DEPENDS cmdline-openfluid-CreateWareSimulator)


###########################################################################


OPENFLUID_ADD_TEST(NAME cmdline-openfluid-CreateWareObserver
COMMAND "${OFBUILD_DIST_BIN_DIR}/${OPENFLUID_CMD_APP}"
"create-ware" "--type=observer" "--id=tests.cmdline.obs"
Expand Down
43 changes: 42 additions & 1 deletion src/openfluid/tools/StringHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

#include <regex>
#include <utility>

#include <boost/algorithm/string.hpp>

#include <openfluid/core/StringValue.hpp>
#include <openfluid/tools/Filesystem.hpp>
#include <openfluid/tools/StringHelpers.hpp>


Expand Down Expand Up @@ -136,6 +136,33 @@ bool contains(const std::string& Str,const std::string& SubStr, bool CaseSensiti
// =====================================================================


std::map<std::string, std::set<std::size_t>> searchInFolder(std::string Folder, std::string String)
{
std::map<std::string, std::set<std::size_t>> OccurencesPosByFile;
for (const auto& E : std::filesystem::recursive_directory_iterator{Folder})
{
auto FileObj = openfluid::tools::Path::fromStdPath(E.path());
const std::string FileContent = openfluid::tools::Filesystem::readFile(FileObj);
auto it = FileContent.find(String);

while (it != std::string::npos)
{
if (OccurencesPosByFile.find(E.path()) == OccurencesPosByFile.end())
{
OccurencesPosByFile[E.path()] = {};
}
OccurencesPosByFile[E.path()].insert(it);
it = FileContent.find(String, it+String.size());
}
}
return OccurencesPosByFile;
}


// =====================================================================
// =====================================================================


std::string replace(const std::string& Str,const std::string& SearchStr, const std::string& ReplaceStr)
{
return boost::replace_all_copy(Str,SearchStr,ReplaceStr);
Expand All @@ -146,6 +173,20 @@ std::string replace(const std::string& Str,const std::string& SearchStr, const s
// =====================================================================


std::string replace_once(const std::string& Str,const std::string& SearchStr, const std::string& ReplaceStr,
std::size_t Pos)
{
std::string Prefix = Str.substr(0,Pos);
std::string SubStr = Str.substr(Pos, Str.size());
std::string Res = boost::replace_first_copy(SubStr,SearchStr,ReplaceStr);
return Prefix+Res;
}


// =====================================================================
// =====================================================================


std::vector<std::string> split(const std::string& Str, const char Sep, bool KeepEmpty)
{
return split(Str,std::string(1,Sep),KeepEmpty);
Expand Down
13 changes: 13 additions & 0 deletions src/openfluid/tools/StringHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <list>
#include <sstream>
#include <vector>
#include <set>

#include <openfluid/base/FrameworkException.hpp>
#include <openfluid/dllexport.hpp>
Expand Down Expand Up @@ -181,6 +182,15 @@ bool OPENFLUID_API endsWith(const std::string& Str,const std::string& SubStr);
bool OPENFLUID_API contains(const std::string& Str,const std::string& SubStr, bool CaseSensitive = true);


/**
Find all occurences of a substring in a folder, iterating on any subdirectory
@param[in] Folder the location to check
@param[in] String the string to look for
@return a map containing the file path associated with a set of string locations in this file
*/
std::map<std::string, std::set<std::size_t>> OPENFLUID_API searchInFolder(std::string Folder, std::string String);


/**
Replaces every occurrence in a string of a searched substring by a replacement substring
@snippet misc/strings.cpp str_repl
Expand All @@ -191,6 +201,9 @@ bool OPENFLUID_API contains(const std::string& Str,const std::string& SubStr, bo
*/
std::string OPENFLUID_API replace(const std::string& Str,const std::string& SearchStr, const std::string& ReplaceStr);

std::string OPENFLUID_API replace_once(const std::string& Str,const std::string& SearchStr,
const std::string& ReplaceStr,
std::size_t Pos);

/**
Formats a string using a format and a variable number of arguments.
Expand Down
2 changes: 2 additions & 0 deletions src/openfluid/ui/waresdev/WareSrcExplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ void WareSrcExplorer::onCustomContextMenuRequested(const QPoint& Point)
if (getCurrentPath().toStdString() ==
openfluid::waresdev::WareSrcEnquirer::getWareInfoFromPath(getCurrentPath().toStdString()).AbsoluteWarePath)
{
Menu.addAction(tr("Duplicate ware"), this, SIGNAL(duplicateWareAsked()));
Menu.addAction(tr("Delete ware"), this, SIGNAL(deleteWareAsked()));

}
else if (!IsRemoveFragment) // "delete folder" is hidden when "remove this fragment" already there
{
Expand Down
2 changes: 2 additions & 0 deletions src/openfluid/ui/waresdev/WareSrcExplorer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class OPENFLUID_API WareSrcExplorer: public QTreeView

void openPathAsked(const QString& FilePath);

void duplicateWareAsked();

void deleteWareAsked();

void fileDeleted(const QString& Path);
Expand Down
Loading
Loading