no message
This commit is contained in:
79
src/_VisualDVM/Repository/BugReport/BugReport.java
Normal file
79
src/_VisualDVM/Repository/BugReport/BugReport.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package _VisualDVM.Repository.BugReport;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Objects.rDBObject;
|
||||
import _VisualDVM.GlobalData.GlobalDatabase;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Repository.Component.ComponentType;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
public class BugReport extends rDBObject {
|
||||
public String project_version = "";
|
||||
public long visualiser_version = -1;
|
||||
public long sapfor_version = -1;
|
||||
public String sapfor_settings = "";
|
||||
public String comment = "";
|
||||
public String targets = "";
|
||||
public String executor = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String executor_address = "";
|
||||
public BugReportState state;
|
||||
public int percentage = 0;
|
||||
//-
|
||||
@Description("IGNORE")
|
||||
public String descriptionAdditionDraft = "";
|
||||
@Description("IGNORE")
|
||||
public String commentAdditionDraft = "";
|
||||
@Description("IGNORE")
|
||||
public File owner = null;
|
||||
public BugReport() {
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
BugReport b = (BugReport) src;
|
||||
change_date = b.change_date;
|
||||
description = b.description;
|
||||
comment = b.comment;
|
||||
targets = b.targets;
|
||||
state = b.state;
|
||||
percentage = b.percentage;
|
||||
//-
|
||||
executor = b.executor;
|
||||
executor_address = b.executor_address;
|
||||
project_version = b.project_version;
|
||||
visualiser_version = b.visualiser_version;
|
||||
sapfor_version = b.sapfor_version;
|
||||
sapfor_settings = b.sapfor_settings;
|
||||
//-
|
||||
descriptionAdditionDraft = b.descriptionAdditionDraft;
|
||||
commentAdditionDraft = b.commentAdditionDraft;
|
||||
owner = b.owner;
|
||||
}
|
||||
public BugReport(BugReport src) {
|
||||
this.SynchronizeFields(src);
|
||||
}
|
||||
|
||||
public BugReport(String sender_name_in, String sender_address_in, String description_in, String version_in) {
|
||||
genName();
|
||||
sender_name = sender_name_in;
|
||||
sender_address = sender_address_in;
|
||||
project_version = version_in;
|
||||
visualiser_version = Global.visualiser.version;
|
||||
sapfor_version = Global.Components.get(ComponentType.Sapfor_F).version;
|
||||
sapfor_settings = ((GlobalDatabase)CommonUtils.db).settings.getSapforSettingsText();
|
||||
percentage = 0;
|
||||
description = description_in;
|
||||
date = new Date().getTime();
|
||||
change_date = new Date().getTime();
|
||||
state = BugReportState.draft;
|
||||
owner = Current.getProject().Home;
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return BugReportInterface.isVisible(this);
|
||||
}
|
||||
}
|
||||
119
src/_VisualDVM/Repository/BugReport/BugReportInterface.java
Normal file
119
src/_VisualDVM/Repository/BugReport/BugReportInterface.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package _VisualDVM.Repository.BugReport;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Utils.TextLog;
|
||||
import _VisualDVM.Repository.RepositoryServer;
|
||||
import _VisualDVM.Repository.Subscribes.Subscriber;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Vector;
|
||||
public class BugReportInterface {
|
||||
public static String filterKey = "";
|
||||
public static String filterSenderName = "";
|
||||
public static String filterDescription = "";
|
||||
public static String filterComment = "";
|
||||
public static String filterExecutor = "";
|
||||
public static String filterVersion = "";
|
||||
public static boolean filterOpenedOnly = false;
|
||||
public static boolean filterMyOnly = false;
|
||||
public static boolean isVisible(BugReport object) {
|
||||
return
|
||||
object.state.equals(BugReportState.draft) ||
|
||||
object.id.toUpperCase().contains(filterKey.toUpperCase())
|
||||
&& object.sender_name.toUpperCase().contains(filterSenderName.toUpperCase())
|
||||
&& object.description.toUpperCase().contains(filterDescription.toUpperCase())
|
||||
&& object.comment.toUpperCase().contains(filterComment.toUpperCase())
|
||||
&& object.executor.toUpperCase().contains(filterExecutor.toUpperCase())
|
||||
&& object.project_version.toUpperCase().contains(filterVersion.toUpperCase())
|
||||
&& (!filterOpenedOnly || object.state.equals(BugReportState.active))
|
||||
&& (!filterMyOnly ||
|
||||
(object.sender_address.equalsIgnoreCase(Current.getAccount().email) ||
|
||||
object.executor_address.equalsIgnoreCase(Current.getAccount().email)
|
||||
)
|
||||
);
|
||||
}
|
||||
public static String getPackedTargets() {
|
||||
Vector<String> selected = new Vector<>();
|
||||
for (Subscriber subscriber : Global.componentsServer.db.subscribers.Data.values())
|
||||
if (subscriber.isSelected()) selected.add(subscriber.address);
|
||||
return String.join("\n", selected);
|
||||
}
|
||||
public static File getArchiveFile(BugReport object) {
|
||||
return Paths.get(System.getProperty("user.dir"), "Bugs", object.id + ".zip").toFile();
|
||||
}
|
||||
public static String getDescriptionHeader(BugReport object) {
|
||||
if (object.description != null) {
|
||||
String[] data = object.description.split("\n");
|
||||
return (data.length > 0) ? data[0] : "";
|
||||
} else return "";
|
||||
}
|
||||
public static void CheckSubscribers(BugReport object) {
|
||||
for (Subscriber subscriber : Global.componentsServer.db.subscribers.Data.values())
|
||||
subscriber.Select(object.targets.contains(subscriber.address));
|
||||
}
|
||||
public static boolean CheckNotDraft(BugReport object, TextLog log) {
|
||||
if (object.state.equals(BugReportState.draft)) {
|
||||
log.Writeln_("Отчёт об ошибке является черновиком");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static String getMailTitlePrefix(BugReport object) {
|
||||
return "Ошибка " + CommonUtils.Brackets(object.id) + ", автор " + CommonUtils.Brackets(object.sender_name) + " : ";
|
||||
}
|
||||
public static Vector<String> getRecipients(BugReport object) {
|
||||
Vector<String> res = new Vector<>();
|
||||
String[] data = object.targets.split("\n");
|
||||
for (String a : data)
|
||||
if (a.length() > 0)
|
||||
res.add(a);
|
||||
if (!res.contains(Current.getAccount().email))
|
||||
res.add(Current.getAccount().email);
|
||||
return res;
|
||||
}
|
||||
public static File[] getAttachements(BugReport object) {
|
||||
File[] project_attachements = Current.getProject().getAttachmentsDirectory().listFiles();
|
||||
File[] res = new File[project_attachements.length + 1];
|
||||
res[0] = getArchiveFile(object);
|
||||
for (int i = 0; i < project_attachements.length; ++i)
|
||||
res[i + 1] = project_attachements[i];
|
||||
return res;
|
||||
}
|
||||
public static boolean CheckDraft(BugReport object, TextLog log) {
|
||||
if (!object.state.equals(BugReportState.draft)) {
|
||||
log.Writeln("Отчёт об ошибке не является черновиком. Он уже опубликован");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static String getNewMailText(BugReport object) {
|
||||
String res = String.join("\n",
|
||||
"Описание:", object.description,
|
||||
getPassport(object)
|
||||
);
|
||||
return res;
|
||||
}
|
||||
public static String getSettingsSummary(BugReport object) {
|
||||
return
|
||||
(Current.HasAccount() ? (Current.getAccount().isAdmin() ? ("Адрес отправителя: " + object.sender_address + "\n") : "") : "") +
|
||||
"Версия SAPFOR: " + object.sapfor_version + "\n" +
|
||||
"Версия визуализатора: " + object.visualiser_version + "\n" +
|
||||
"----------------------------------\n" +
|
||||
object.sapfor_settings;
|
||||
}
|
||||
public static String getPassport(BugReport object) {
|
||||
return String.join("\n",
|
||||
RepositoryServer.separator,
|
||||
"Отправитель: " + object.sender_name,
|
||||
"Исполнитель: " + object.executor,
|
||||
"Проект: " + object.project_version,
|
||||
RepositoryServer.separator,
|
||||
getSettingsSummary(object),
|
||||
RepositoryServer.separator);
|
||||
}
|
||||
public static boolean isNoneProject(BugReport object) {
|
||||
return object.project_version.isEmpty();
|
||||
}
|
||||
}
|
||||
33
src/_VisualDVM/Repository/BugReport/BugReportState.java
Normal file
33
src/_VisualDVM/Repository/BugReport/BugReportState.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package _VisualDVM.Repository.BugReport;
|
||||
import Common.Visual.StatusEnum;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
|
||||
import java.io.Serializable;
|
||||
public enum BugReportState implements Serializable, StatusEnum {
|
||||
active,
|
||||
closed,
|
||||
draft;
|
||||
@Override
|
||||
public VisualiserFonts getFont() {
|
||||
switch (this) {
|
||||
case active:
|
||||
return VisualiserFonts.BadState;
|
||||
case closed:
|
||||
return VisualiserFonts.GoodState;
|
||||
default:
|
||||
return StatusEnum.super.getFont();
|
||||
}
|
||||
}
|
||||
public String getDescription() {
|
||||
switch (this) {
|
||||
case draft:
|
||||
return "черновик";
|
||||
case active:
|
||||
return "открыт";
|
||||
case closed:
|
||||
return "закрыт";
|
||||
default:
|
||||
return StatusEnum.super.getDescription();
|
||||
}
|
||||
}
|
||||
}
|
||||
115
src/_VisualDVM/Repository/BugReport/BugReportsDBTable.java
Normal file
115
src/_VisualDVM/Repository/BugReport/BugReportsDBTable.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package _VisualDVM.Repository.BugReport;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import _VisualDVM.Visual.UI;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Comparator;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static Common.Visual.Tables.TableRenderers.*;
|
||||
public class BugReportsDBTable extends DBTable<String, BugReport> {
|
||||
public BugReportsDBTable() {
|
||||
super(String.class, BugReport.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "отчёт об ошибке";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "отчёты об ошибках";
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI() {
|
||||
return new DataSetControlForm(this) {
|
||||
@Override
|
||||
public void ShowCurrentObject() throws Exception {
|
||||
super.ShowCurrentObject();
|
||||
UI.getMainWindow().getCallbackWindow().ShowCurrentBugReport();
|
||||
}
|
||||
@Override
|
||||
public void ShowNoCurrentObject() throws Exception {
|
||||
super.ShowNoCurrentObject();
|
||||
UI.getMainWindow().getCallbackWindow().ShowNoCurrentBugReport();
|
||||
}
|
||||
@Override
|
||||
protected void AdditionalInitColumns() {
|
||||
columns.get(1).setMaxWidth(600);
|
||||
columns.get(5).setRenderer(RendererProgress);
|
||||
columns.get(6).setRenderer(RendererDate);
|
||||
columns.get(7).setRenderer(RendererDate);
|
||||
columns.get(8).setRenderer(RendererStatusEnum);
|
||||
}
|
||||
@Override
|
||||
public void MouseAction2() throws Exception {
|
||||
Pass_2021.passes.get(PassCode_2021.OpenBugReportTestProject).Do();
|
||||
}
|
||||
@Override
|
||||
public void CreateControl() {
|
||||
//https://stackoverflow.com/questions/9091208/jtable-enter-key
|
||||
super.CreateControl();
|
||||
final String solve = "Solve";
|
||||
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
|
||||
control.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, solve);
|
||||
control.getActionMap().put(solve, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Pass_2021.passes.get(PassCode_2021.OpenBugReportTestProject).Do();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public Comparator<BugReport> getComparator() {
|
||||
return (o1, o2) -> -(o1.getDate().compareTo(o2.getDate()));
|
||||
}
|
||||
@Override
|
||||
public String[] getUIColumnNames() {
|
||||
return new String[]{"Описание",
|
||||
"Отправитель",
|
||||
"Исполнитель",
|
||||
"Проект",
|
||||
"Завершенность",
|
||||
"Дата создания",
|
||||
"Дата изменения",
|
||||
"Статус"};
|
||||
}
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 1:
|
||||
return BugReportInterface.getDescriptionHeader(object);
|
||||
case 2:
|
||||
return object.sender_name;
|
||||
case 3:
|
||||
return object.executor;
|
||||
case 4:
|
||||
return object.project_version;
|
||||
case 5:
|
||||
return object.percentage;
|
||||
case 6:
|
||||
return object.getDate();
|
||||
case 7:
|
||||
return object.getChangeDate();
|
||||
case 8:
|
||||
return object.state;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Current CurrentName() {
|
||||
return Current.BugReport;
|
||||
}
|
||||
public Vector<BugReport> getAllDrafts() throws Exception {
|
||||
return Data.values().stream().filter(bugReport -> bugReport.state.equals(BugReportState.draft)).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
}
|
||||
17
src/_VisualDVM/Repository/BugReport/BugReportsMenuBar.java
Normal file
17
src/_VisualDVM/Repository/BugReport/BugReportsMenuBar.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package _VisualDVM.Repository.BugReport;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
public class BugReportsMenuBar extends DataMenuBar {
|
||||
public BugReportsMenuBar() {
|
||||
super("отчёты об ошибках",
|
||||
PassCode_2021.SynchronizeBugReports,
|
||||
PassCode_2021.DownloadAllBugReportsArchives,
|
||||
PassCode_2021.AddBugReport,
|
||||
PassCode_2021.PublishBugReport,
|
||||
PassCode_2021.OpenBugReportTestProject,
|
||||
PassCode_2021.OpenBugReport,
|
||||
PassCode_2021.UpdateBugReportProgress,
|
||||
PassCode_2021.CloseBugReport,
|
||||
PassCode_2021.DeleteBugReport);
|
||||
}
|
||||
}
|
||||
38
src/_VisualDVM/Repository/BugReportsDatabase.java
Normal file
38
src/_VisualDVM/Repository/BugReportsDatabase.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package _VisualDVM.Repository;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Repository.BugReport.BugReport;
|
||||
import _VisualDVM.Repository.BugReport.BugReportsDBTable;
|
||||
import _VisualDVM.Repository.SubscriberWorkspace.SubscriberWorkspaceDBTable;
|
||||
import _VisualDVM.Repository.Subscribes.SubsribersDBTable;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Vector;
|
||||
public class BugReportsDatabase extends SQLiteDatabase {
|
||||
public BugReportsDBTable bugReports;
|
||||
public SubsribersDBTable subscribers;
|
||||
public SubscriberWorkspaceDBTable workspaces; //рабочие пространства для машин.
|
||||
public BugReportsDatabase() {
|
||||
super(Paths.get(System.getProperty("user.dir"), "Data", Global.properties.BugReportsDBName).toFile());
|
||||
}
|
||||
@Override
|
||||
protected void initAllTables() throws Exception {
|
||||
addTable(bugReports = new BugReportsDBTable());
|
||||
addTable(subscribers = new SubsribersDBTable());
|
||||
addTable(workspaces = new SubscriberWorkspaceDBTable());
|
||||
}
|
||||
@Override
|
||||
public void Init() throws Exception {
|
||||
DeleteDrafts();
|
||||
}
|
||||
@Override
|
||||
public PassCode_2021 getSynchronizePassCode() {
|
||||
return PassCode_2021.SynchronizeBugReports;
|
||||
}
|
||||
public void DeleteDrafts() throws Exception {
|
||||
Vector<BugReport> drafts = bugReports.getAllDrafts();
|
||||
for (BugReport draft : drafts)
|
||||
Delete(draft);
|
||||
}
|
||||
}
|
||||
140
src/_VisualDVM/Repository/Component/Component.java
Normal file
140
src/_VisualDVM/Repository/Component/Component.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.CommonConstants;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Constants;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Visual.Windows.Dialog.VFileChooser;
|
||||
import Common.Utils.TextLog;
|
||||
import _VisualDVM.Utils;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Common.Utils.Loggable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
public abstract class Component extends DBObject implements Loggable {
|
||||
public String date_text = Constants.dateNaN;
|
||||
public long version = CommonConstants.Nan;
|
||||
public long actual_version = CommonConstants.Nan;
|
||||
public long minimal_version = CommonConstants.Nan;
|
||||
//--
|
||||
public String code = "";
|
||||
public String actual_code = "";
|
||||
public boolean needs_update_minimal_version = false;
|
||||
private ComponentState state;
|
||||
public abstract ComponentType getComponentType();
|
||||
VFileChooser fileChooser = null; ///для ручной установки.
|
||||
public VFileChooser getFileChooser() {
|
||||
return (fileChooser == null) ? (fileChooser = new VFileChooser("выбор файла для компонента " +
|
||||
CommonUtils.Brackets(getComponentType().getDescription()), CommonUtils.getExtension(getFile())))
|
||||
: fileChooser;
|
||||
}
|
||||
//--
|
||||
public String getVersionText() {
|
||||
return String.valueOf(version);
|
||||
}
|
||||
public void CheckIfNeedsUpdateOrPublish() {
|
||||
if (actual_version != CommonConstants.Nan) {
|
||||
if (version < minimal_version) setState(ComponentState.Old_version);
|
||||
else {
|
||||
ComponentState new_state =
|
||||
(actual_version > version) ? ComponentState.Needs_update : (
|
||||
(actual_version < version) ? ComponentState.Needs_publish : ComponentState.Actual);
|
||||
setState(new_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void InitialVersionCheck() {
|
||||
setState(ComponentState.Undefined);
|
||||
if (getFile().exists()) {
|
||||
GetVersionInfo();
|
||||
if (version == CommonConstants.Nan)
|
||||
setState(ComponentState.Unknown_version);
|
||||
} else setState(ComponentState.Not_found);
|
||||
}
|
||||
public boolean CanBeUpdated() {
|
||||
return state != ComponentState.Not_found && state != ComponentState.Unknown_version && state != ComponentState.Old_version;
|
||||
}
|
||||
public void GetVersionInfo() {
|
||||
}
|
||||
public void unpackActualVersion(String v_string) {
|
||||
actual_version = Long.parseLong(v_string);
|
||||
}
|
||||
public void unpackMinimalVersion(String v_string) {
|
||||
minimal_version = Long.parseLong(v_string);
|
||||
}
|
||||
public void ReplaceOldFile() throws Exception {
|
||||
Utils.delete_with_check(getFile());
|
||||
//-скопировать файл
|
||||
Files.move(getNewFile().toPath(), getFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
//удалить новый файл.
|
||||
Utils.delete_with_check(getNewFile());
|
||||
}
|
||||
public void Update() throws Exception {
|
||||
if (!getNewFile().setExecutable(true)) throw new PassException("Не удалось разрешить файл\n" +
|
||||
getNewFile() +
|
||||
"\nна выполнение");
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return getComponentType();
|
||||
}
|
||||
public boolean isValidVersion(TextLog Log, String desc) {
|
||||
if (version == CommonConstants.Nan) {
|
||||
Log.Writeln_("Не определена версия " + desc + " компонента " + CommonUtils.Brackets(getComponentType().getDescription()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------>>>
|
||||
public String getHome() {
|
||||
return Global.ComponentsDirectory.getAbsolutePath();
|
||||
}
|
||||
public String getFileName() {
|
||||
return "";
|
||||
}
|
||||
public String getNewFileName() {
|
||||
return "";
|
||||
}
|
||||
public String getBackUpFileName() {
|
||||
return getComponentType().toString() + "_" + version;
|
||||
}
|
||||
public File getFile() {
|
||||
return Paths.get(getHome(), getFileName()).toFile();
|
||||
}
|
||||
public File getNewFile() {
|
||||
return Paths.get(getHome(), getNewFileName()).toFile();
|
||||
}
|
||||
public File getBackUpFile() {
|
||||
return Paths.get(Global.BackUpsDirectory.getAbsolutePath(), getBackUpFileName()).toFile();
|
||||
}
|
||||
public ComponentState getState() {
|
||||
return state;
|
||||
}
|
||||
public void setState(ComponentState state_in) {
|
||||
state = state_in;
|
||||
}
|
||||
public String getAssemblyCommand() {
|
||||
return "";
|
||||
}
|
||||
public File getAssemblyFile() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getLogHomePath() {
|
||||
return Global.ComponentsDirectory.getAbsolutePath();
|
||||
}
|
||||
@Override
|
||||
public String getLogName() {
|
||||
return getComponentType().toString();
|
||||
}
|
||||
public boolean isNecessary() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
47
src/_VisualDVM/Repository/Component/ComponentState.java
Normal file
47
src/_VisualDVM/Repository/Component/ComponentState.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.Visual.StatusEnum;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
public enum ComponentState implements StatusEnum {
|
||||
Undefined,
|
||||
Actual,
|
||||
Needs_update,
|
||||
Not_found,
|
||||
Old_version,
|
||||
Needs_publish,
|
||||
Unknown_version;
|
||||
@Override
|
||||
public VisualiserFonts getFont() {
|
||||
switch (this) {
|
||||
case Actual:
|
||||
return VisualiserFonts.GoodState;
|
||||
case Not_found:
|
||||
case Unknown_version:
|
||||
case Old_version:
|
||||
return VisualiserFonts.BadState;
|
||||
case Needs_update:
|
||||
return VisualiserFonts.ProgressState;
|
||||
case Needs_publish:
|
||||
return VisualiserFonts.BlueState;
|
||||
default:
|
||||
return StatusEnum.super.getFont();
|
||||
}
|
||||
}
|
||||
public String getDescription() {
|
||||
switch (this) {
|
||||
case Actual:
|
||||
return "актуален";
|
||||
case Not_found:
|
||||
return "не найден";
|
||||
case Old_version:
|
||||
return "устаревшая версия";
|
||||
case Needs_update:
|
||||
return "найдено обновление";
|
||||
case Needs_publish:
|
||||
return "ожидает публикации";
|
||||
case Unknown_version:
|
||||
return "не удалось определить версию";
|
||||
default:
|
||||
return StatusEnum.super.getDescription();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/_VisualDVM/Repository/Component/ComponentType.java
Normal file
35
src/_VisualDVM/Repository/Component/ComponentType.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import java.io.Serializable;
|
||||
public enum ComponentType implements Serializable {
|
||||
Undefined,
|
||||
//внутренние
|
||||
Visualiser, //возможно к нему привязать VisualSapfor.jar
|
||||
Visualizer_2,
|
||||
SapforOptions,
|
||||
ComparsionOptions,
|
||||
SapforWrapper, //todo ЗАЧЕМ???
|
||||
//---------------------
|
||||
//------------------
|
||||
Sapfor_F,
|
||||
Sapfor_C,
|
||||
Instruction,
|
||||
PerformanceAnalyzer;
|
||||
//------------------
|
||||
public String getDescription() {
|
||||
String res = "";
|
||||
switch (this) {
|
||||
case Visualiser:
|
||||
return "Визуализатор";
|
||||
case Sapfor_F:
|
||||
return "Sapfor (Fortran)";
|
||||
case Visualizer_2:
|
||||
return "Сервер";
|
||||
case Instruction:
|
||||
return "Инструкция";
|
||||
case PerformanceAnalyzer:
|
||||
return "Анализатор DVM статистик";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/_VisualDVM/Repository/Component/ComponentsMenuBar.java
Normal file
27
src/_VisualDVM/Repository/Component/ComponentsMenuBar.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import _VisualDVM.Visual.Menus.VisualiserMenu;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
public class ComponentsMenuBar extends DataMenuBar {
|
||||
public ComponentsMenuBar() {
|
||||
super("компоненты");
|
||||
addMenus(
|
||||
new VisualiserMenu(
|
||||
"Восстановление предыдущей версии компонента", "/icons/Resurrect.png") {
|
||||
{
|
||||
setFont(CommonUI.getTheme().Fonts.get(VisualiserFonts.Menu));
|
||||
add(Pass_2021.passes.get(PassCode_2021.ResurrectComponent).createMenuItem());
|
||||
add(Pass_2021.passes.get(PassCode_2021.ResurrectComponentFromServer).createMenuItem());
|
||||
}
|
||||
}
|
||||
);
|
||||
addPasses(PassCode_2021.InstallComponentFromFolder,
|
||||
PassCode_2021.UpdateSelectedComponents,
|
||||
PassCode_2021.PublishComponent,
|
||||
PassCode_2021.ShowComponentChangesLog);
|
||||
Pass_2021.passes.get(PassCode_2021.PublishComponent).setControlsVisible(false);
|
||||
}
|
||||
}
|
||||
88
src/_VisualDVM/Repository/Component/ComponentsSet.java
Normal file
88
src/_VisualDVM/Repository/Component/ComponentsSet.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import static Common.Visual.Tables.TableRenderers.RendererMaskedInt;
|
||||
import static Common.Visual.Tables.TableRenderers.RendererStatusEnum;
|
||||
public class ComponentsSet extends DataSet<ComponentType, Component> {
|
||||
public ComponentsSet() {
|
||||
super(ComponentType.class, Component.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "компонент";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "компоненты";
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI() {
|
||||
return new DataSetControlForm(this) {
|
||||
@Override
|
||||
public boolean hasCheckBox() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected void AdditionalInitColumns() {
|
||||
columns.get(0).setVisible(false);
|
||||
columns.get(3).setRenderer(RendererMaskedInt);
|
||||
columns.get(4).setRenderer(RendererMaskedInt);
|
||||
columns.get(6).setRenderer(RendererStatusEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public String[] getUIColumnNames() {
|
||||
return new String[]{"Компонент", "Текущая версия", "Актуальная версия", "Дата сборки", "Статус"};
|
||||
}
|
||||
@Override
|
||||
public Object getFieldAt(Component object, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 2:
|
||||
return object.getComponentType().getDescription();
|
||||
case 3:
|
||||
return object.version;
|
||||
case 4:
|
||||
return object.actual_version;
|
||||
case 5:
|
||||
return object.date_text;
|
||||
case 6:
|
||||
return object.getState();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Current CurrentName() {
|
||||
return Current.Component;
|
||||
}
|
||||
@Override
|
||||
public Vector<Component> getCheckedItems() {
|
||||
Vector<Component> target = new Vector<>();
|
||||
Component visualiser = null;
|
||||
Component server = null;
|
||||
//------------------------
|
||||
for (Component component : super.getCheckedItems()) {
|
||||
switch (component.getComponentType()) {
|
||||
case Visualizer_2:
|
||||
server = component;
|
||||
break;
|
||||
case Visualiser:
|
||||
visualiser = component;
|
||||
break;
|
||||
default:
|
||||
target.add(component);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (visualiser != null)
|
||||
target.add(visualiser);
|
||||
if (server != null)
|
||||
target.add(server);
|
||||
return target;
|
||||
}
|
||||
}
|
||||
57
src/_VisualDVM/Repository/Component/Instruction.java
Normal file
57
src/_VisualDVM/Repository/Component/Instruction.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Utils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
public class Instruction extends Component {
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "Instruction.pdf";
|
||||
}
|
||||
@Override
|
||||
public String getNewFileName() {
|
||||
return "Instruction_new.pdf";
|
||||
}
|
||||
@Override
|
||||
public boolean isNecessary() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public ComponentType getComponentType() {
|
||||
return ComponentType.Instruction;
|
||||
}
|
||||
public void Update() throws Exception {
|
||||
ReplaceOldFile();
|
||||
GetVersionInfo();
|
||||
actual_version = 1;
|
||||
}
|
||||
@Override
|
||||
public String getVersionText() {
|
||||
return code;
|
||||
}
|
||||
//вызывается в первую очередь
|
||||
@Override
|
||||
public void unpackActualVersion(String v_string) {
|
||||
actual_code = v_string;
|
||||
actual_version = code.isEmpty() ? 1 : ((code.equals(actual_code)) ? 1 : 2);
|
||||
if (CanBeUpdated())
|
||||
CheckIfNeedsUpdateOrPublish();
|
||||
}
|
||||
@Override
|
||||
public void unpackMinimalVersion(String v_string) {
|
||||
//--
|
||||
}
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
version = 1;
|
||||
code = Utils.md5Custom(Utils.ReadAllText(getFile()));
|
||||
DateFormat df = new SimpleDateFormat("MMM dd yyyy HH:mm:ss", Locale.ENGLISH);
|
||||
date_text = df.format(getFile().lastModified());
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/_VisualDVM/Repository/Component/OSDComponent.java
Normal file
12
src/_VisualDVM/Repository/Component/OSDComponent.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.Utils.CommonUtils;
|
||||
public abstract class OSDComponent extends Component {
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return getComponentType().toString() + (CommonUtils.isWindows() ? ".exe" : "");
|
||||
}
|
||||
@Override
|
||||
public String getNewFileName() {
|
||||
return getComponentType().toString() + "_new" + (CommonUtils.isWindows() ? ".exe" : "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package _VisualDVM.Repository.Component.PerformanceAnalyzer;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.Global;
|
||||
import analyzer.common.MessageJtoJ;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.Repository.Component.Component;
|
||||
import _VisualDVM.Repository.Component.ComponentType;
|
||||
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.Callable;
|
||||
public class PerformanceAnalyzer extends Component {
|
||||
public static boolean isActive = false;
|
||||
public static Thread main_thread = null;
|
||||
ServerSocket serverSocket = null;
|
||||
Socket client = null;
|
||||
Thread process_thread = null;
|
||||
Thread server_thread = null;
|
||||
//<editor-fold desc="серверная часть">
|
||||
private int port;
|
||||
private ObjectInputStream in; // поток чтения из сокета
|
||||
private ObjectOutputStream out; // поток записи в сокет
|
||||
private MessageJtoJ message_out = null;
|
||||
private MessageJtoJ message_in = null;
|
||||
@Override
|
||||
public ComponentType getComponentType() {
|
||||
return ComponentType.PerformanceAnalyzer;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
public void Update() throws Exception {
|
||||
ReplaceOldFile();
|
||||
GetVersionInfo();
|
||||
}
|
||||
@Override
|
||||
public boolean isNecessary() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "PerformanceAnalyzer.jar";
|
||||
}
|
||||
@Override
|
||||
public String getNewFileName() {
|
||||
return "PerformanceAnalyzer_new.jar";
|
||||
}
|
||||
public void Shutdown() {
|
||||
try {
|
||||
if (client != null) {
|
||||
client.setSoLinger(true, 500);
|
||||
client.close();
|
||||
}
|
||||
if (serverSocket != null) serverSocket.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
public void ReadMessageIn() throws Exception {
|
||||
message_in = (MessageJtoJ) in.readObject();
|
||||
}
|
||||
public void SendMessageOut(MessageJtoJ messageJtoJ) throws Exception {
|
||||
message_out = messageJtoJ;
|
||||
out.writeObject(message_out);
|
||||
}
|
||||
public void ConvertStatistic() throws Exception {
|
||||
message_in = (MessageJtoJ) in.readObject();
|
||||
String message = Current.getSapfor().readStatForAnalyzer(message_in.getMessage());
|
||||
message_out = new MessageJtoJ(message, message_in.getCommand());
|
||||
out.writeObject(message_out);
|
||||
}
|
||||
public void StartServer(Callable body) throws Exception {
|
||||
serverSocket = new ServerSocket(0, 5, InetAddress.getLoopbackAddress());
|
||||
setPort(serverSocket.getLocalPort());
|
||||
server_thread = new Thread(() -> {
|
||||
try {
|
||||
client = serverSocket.accept();
|
||||
out = new ObjectOutputStream(client.getOutputStream());
|
||||
in = new ObjectInputStream(client.getInputStream());
|
||||
//------------------------------------------------------->>;
|
||||
body.call();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
server_thread.start();
|
||||
}
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
StartServer(() -> {
|
||||
ReadMessageIn(); //на версию.
|
||||
version = (long) Double.parseDouble(message_in.getMessage());
|
||||
ReadMessageIn(); //на дату.
|
||||
date_text = message_in.getMessage();
|
||||
return null;
|
||||
});
|
||||
Utils.startScript(Global.TempDirectory, Global.ComponentsDirectory, "analyzer",
|
||||
"java -jar -Dprism.order=sw "+ CommonUtils.DQuotes(Global.performanceAnalyzer.getFile()) + " --port "+ getPort()+ " --version" );
|
||||
//-
|
||||
server_thread.join();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
public void ServerBody() {
|
||||
//1. нить сервера. слушать.
|
||||
try {
|
||||
StartServer(() -> {
|
||||
SendMessageOut(new MessageJtoJ(
|
||||
Current.HasProject() ? Current.getProject().getAnalyzerDirectory().getAbsolutePath() : Global.PerformanceAnalyzerDirectory.getAbsolutePath(), "StatDirPath"));
|
||||
while (true) ConvertStatistic();
|
||||
});
|
||||
// UI.Info(String.valueOf(getPort()));
|
||||
process_thread = new Thread(() -> {
|
||||
try {
|
||||
|
||||
Utils.startScript(Global.TempDirectory, Global.ComponentsDirectory, "analyzer",
|
||||
"java -jar -Dprism.order=sw "+ CommonUtils.DQuotes(Global.performanceAnalyzer.getFile()) + " --port "+ getPort());
|
||||
//-
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
process_thread.start();
|
||||
isActive = true;
|
||||
process_thread.join();
|
||||
server_thread.join();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
Shutdown();
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
public void Start() {
|
||||
if (isActive) {
|
||||
CommonUI.Info("Анализатор уже запущен");
|
||||
} else {
|
||||
main_thread = new Thread(this::ServerBody);
|
||||
main_thread.start();
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Current;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
public class MessagesServer {
|
||||
ServerSocket serverSocket = null;
|
||||
Socket client = null;
|
||||
Thread thread = null;
|
||||
private int port;
|
||||
public MessagesServer() throws Exception {
|
||||
serverSocket = new ServerSocket(0, 5, InetAddress.getLoopbackAddress());
|
||||
setPort(serverSocket.getLocalPort());
|
||||
}
|
||||
public MessagesServer(int port_in) {
|
||||
port = port_in;
|
||||
}
|
||||
public void Start() {
|
||||
thread = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
client = serverSocket.accept();
|
||||
BufferedReader in = new BufferedReader(new
|
||||
InputStreamReader(client.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (Current.HasPassForm())
|
||||
Current.getPassForm().Result.ShowSapforMessage(line);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// UI.Print(DebugPrintLevel.MessagesServer, "соединение сброшено!");
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
public void Shutdown() {
|
||||
try {
|
||||
if (client != null) {
|
||||
client.setSoLinger(true, 500);
|
||||
client.close();
|
||||
}
|
||||
if (serverSocket != null)
|
||||
serverSocket.close();
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
588
src/_VisualDVM/Repository/Component/Sapfor/Sapfor.java
Normal file
588
src/_VisualDVM/Repository/Component/Sapfor/Sapfor.java
Normal file
@@ -0,0 +1,588 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
import Common.CommonConstants;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.GlobalData.GlobalDatabase;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.UI;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.GlobalData.Settings.SettingName;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.ProjectData.Files.LanguageStyle;
|
||||
import _VisualDVM.Repository.Component.OSDComponent;
|
||||
import _VisualDVM.Repository.Component.Visualizer_2;
|
||||
import _VisualDVM.TestingSystem.Common.Test.Test;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public abstract class Sapfor extends OSDComponent {
|
||||
public static final int empty_code = -100;
|
||||
public static final int canceled_code = -99;
|
||||
public static final int invalid_proj_code = -2;
|
||||
public Vector<String> Intrinsics = new Vector<>();
|
||||
public LinkedHashMap<String, String> ModifiedFiles = new LinkedHashMap<>();
|
||||
public LinkedHashMap<String, String> OldFiles = new LinkedHashMap<>();
|
||||
int size;
|
||||
int[] sizes;
|
||||
private int errorCode;
|
||||
private String result;
|
||||
private String output;
|
||||
private String outputMessage;
|
||||
private String predictorStats;
|
||||
String PID = "";
|
||||
//-
|
||||
public static String pack(String... params) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String param : params)
|
||||
res.append(param.length()).append(" ").append(param);
|
||||
return res.toString();
|
||||
}
|
||||
public void refreshPid() {
|
||||
try {
|
||||
// UI.Info("Calling SPF_GetCurrentPID...");
|
||||
RunAnalysis("SPF_GetCurrentPID", -1, "", "");
|
||||
PID = getResult();
|
||||
// UI.Info("PID = " + Utils.Brackets(PID));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static PassCode_2021[] getAnalysesCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_ParseFilesWithOrder,
|
||||
PassCode_2021.SPF_GetFileLineInfo,
|
||||
PassCode_2021.SPF_GetArrayDistributionOnlyRegions,
|
||||
PassCode_2021.SPF_GetIncludeDependencies,
|
||||
PassCode_2021.SPF_GetGraphLoops,
|
||||
PassCode_2021.SPF_GetGraphFunctions,
|
||||
PassCode_2021.SPF_GetAllDeclaratedArrays,
|
||||
PassCode_2021.SPF_GetArrayDistributionOnlyAnalysis,
|
||||
PassCode_2021.SPF_GetArrayDistribution
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getLoopsTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_LoopEndDoConverterPass,
|
||||
PassCode_2021.SPF_LoopFission,
|
||||
PassCode_2021.SPF_LoopUnion,
|
||||
PassCode_2021.SPF_LoopUnrolling
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getPrivatesTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_PrivateShrinking,
|
||||
PassCode_2021.SPF_PrivateExpansion,
|
||||
PassCode_2021.SPF_PrivateRemoving,
|
||||
PassCode_2021.SPF_InsertPrivateFromGUI
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getProceduresTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_InlineProcedures,
|
||||
PassCode_2021.SPF_InlineProceduresH,
|
||||
PassCode_2021.SPF_DuplicateFunctionChains,
|
||||
PassCode_2021.SPF_RemoveUnusedFunctions
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getDVMTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_RemoveDvmDirectivesToComments,
|
||||
PassCode_2021.SPF_RemoveDvmDirectives,
|
||||
PassCode_2021.SPF_RemoveOmpDirectives
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getIntervalsTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_CreateIntervalsTree,
|
||||
PassCode_2021.SPF_RemoveDvmIntervals
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getRegionsTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_ResolveParallelRegionConflicts,
|
||||
PassCode_2021.SPF_InsertDvmhRegions
|
||||
};
|
||||
}
|
||||
public static PassCode_2021[] getPreparationTransformationsCodes() {
|
||||
return new PassCode_2021[]{
|
||||
PassCode_2021.SPF_RenameIncludes,
|
||||
PassCode_2021.SPF_InsertIncludesPass,
|
||||
PassCode_2021.SPF_CorrectCodeStylePass,
|
||||
PassCode_2021.SPF_ConvertStructures,
|
||||
PassCode_2021.SPF_CreateCheckpoints,
|
||||
PassCode_2021.SPF_InitDeclsWithZero,
|
||||
PassCode_2021.SPF_ExpressionSubstitution,
|
||||
PassCode_2021.EraseBadSymbols,
|
||||
PassCode_2021.SPF_RemoveComments,
|
||||
PassCode_2021.SPF_RemoveDeadCode,
|
||||
PassCode_2021.CombineFiles,
|
||||
PassCode_2021.CopyProject,
|
||||
PassCode_2021.PrepareForModulesAssembly,
|
||||
PassCode_2021.DVMConvertProject,
|
||||
PassCode_2021.SPF_ResolveCommonBlockConflicts,
|
||||
PassCode_2021.SPF_InsertImplicitNone
|
||||
};
|
||||
}
|
||||
//<editor-fold desc="компонент">
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
RunAnalysis("SPF_GetVersionAndBuildDate", -1, "", "");
|
||||
Visualizer_2.UnpackVersionInfo(this, getResult());
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
CommonUI.Error("Не удалось получить версию компонента " + CommonUtils.DQuotes(getComponentType().getDescription()));
|
||||
}
|
||||
}
|
||||
public abstract String getUpdateCommand();
|
||||
public abstract String getRestartCommand();
|
||||
@Override
|
||||
public void Update() throws Exception {
|
||||
super.Update();
|
||||
Global.visualizer_2.Command(getUpdateCommand());
|
||||
GetVersionInfo();
|
||||
ResetAllAnalyses();
|
||||
refreshPid();
|
||||
}
|
||||
//</editor-fold>
|
||||
//--------
|
||||
//<editor-fold desc="функционал">
|
||||
public String readStatForAnalyzer(String src) throws Exception {
|
||||
RunAnalysis(
|
||||
"SPF_OpenDvmStatistic",
|
||||
-Global.messagesServer.getPort(),
|
||||
Global.packSapforSettings(),
|
||||
src);
|
||||
return result;
|
||||
}
|
||||
public void readStatToTxt(File src, File dst) throws Exception {
|
||||
RunAnalysis("SPF_StatisticAnalyzer",
|
||||
-1,
|
||||
"",
|
||||
CommonUtils.DQuotes(src.getAbsolutePath()) +
|
||||
" "
|
||||
+ CommonUtils.DQuotes(dst.getAbsolutePath())
|
||||
);
|
||||
}
|
||||
public void Restart() throws Exception {
|
||||
ResetAllAnalyses();
|
||||
Global.visualizer_2.Command(getRestartCommand());
|
||||
refreshPid();
|
||||
}
|
||||
public void Interrupt() throws Exception {
|
||||
Utils.Kill(PID, true);
|
||||
}
|
||||
public void cd(File directory_in) throws Exception {
|
||||
if (RunAnalysis("SPF_ChangeDirectory", -1, directory_in.getAbsolutePath(), "") != 0)
|
||||
throw new PassException("Sapfor: Не удалось перейти в папку "
|
||||
+ CommonUtils.Brackets(directory_in.getAbsolutePath()) +
|
||||
"\n" + "Код возврата: " + getErrorCode());
|
||||
}
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
public void setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
public String getOutput() {
|
||||
return output;
|
||||
}
|
||||
public void setOutput(String output) {
|
||||
this.output = output;
|
||||
}
|
||||
public String getOutputMessage() {
|
||||
return outputMessage;
|
||||
}
|
||||
public void setOutputMessage(String outputMessage) {
|
||||
this.outputMessage = outputMessage;
|
||||
}
|
||||
public String getPredictorStats() {
|
||||
return predictorStats;
|
||||
}
|
||||
public void setPredictorStats(String predictorStats) {
|
||||
this.predictorStats = predictorStats;
|
||||
}
|
||||
public void decodeString(String runResult) throws Exception {
|
||||
int codeIdx = runResult.indexOf(' ');
|
||||
if (codeIdx == -1) throw new PassException("Wrong input parameter");
|
||||
setErrorCode(Integer.parseInt(runResult.substring(0, codeIdx)));
|
||||
int lastCodeIdx = 0, count = 0;
|
||||
// for analysis and transformation
|
||||
for (int z = 0; z < 4; ++z) {
|
||||
lastCodeIdx = codeIdx;
|
||||
codeIdx = runResult.indexOf(' ', codeIdx + 1);
|
||||
if (codeIdx == -1) throw new PassException("Wrong input parameter");
|
||||
count = Integer.parseInt(runResult.substring(lastCodeIdx + 1, codeIdx));
|
||||
String sub = runResult.substring(codeIdx + 1, codeIdx + 1 + count);
|
||||
if (z == 0) setResult(sub);
|
||||
else if (z == 1) setOutput(sub);
|
||||
else if (z == 2) setOutputMessage(sub);
|
||||
else if (z == 3) setPredictorStats(sub);
|
||||
codeIdx += count;
|
||||
}
|
||||
// for modification
|
||||
String file_text = null;
|
||||
if (codeIdx + 1 + count < runResult.length())
|
||||
for (int z = 0; z < 3; ++z) {
|
||||
lastCodeIdx = codeIdx;
|
||||
codeIdx = runResult.indexOf(' ', codeIdx + 1);
|
||||
if (codeIdx == -1) throw new PassException("Wrong input parameter");
|
||||
count = Integer.parseInt(runResult.substring(lastCodeIdx + 1, codeIdx));
|
||||
String sub = runResult.substring(codeIdx + 1, codeIdx + 1 + count);
|
||||
if (z == 0) {
|
||||
String[] splited = sub.split("\\|");
|
||||
if (splited.length == 0 || sub.length() == 0)
|
||||
size = 0;
|
||||
else {
|
||||
size = splited.length - 1;
|
||||
sizes = new int[splited.length];
|
||||
for (int k = 0; k < size + 1; ++k)
|
||||
sizes[k] = Integer.parseInt(splited[k]);
|
||||
}
|
||||
} else if (z == 1) file_text = sub;
|
||||
else if (z == 2) {
|
||||
ModifiedFiles.put(CommonUtils.toW(sub), file_text);
|
||||
file_text = null;
|
||||
}
|
||||
codeIdx += count;
|
||||
}
|
||||
}
|
||||
//-
|
||||
public void Command(String request_in) throws Exception {
|
||||
setErrorCode(empty_code);
|
||||
outputMessage = output = result = predictorStats = "";
|
||||
size = 0;
|
||||
sizes = null;
|
||||
ModifiedFiles.clear();
|
||||
//модификации.-------------------------------------------------------------->>>>
|
||||
decodeString(Global.visualizer_2.Command(request_in).replace((char) 1, '\n'));
|
||||
}
|
||||
//-
|
||||
public int RunAnalysis(String analysisName,
|
||||
int winHandler,
|
||||
String options,
|
||||
String projName) throws Exception {
|
||||
Command("analysis:" + pack(analysisName, options, projName) + winHandler);
|
||||
return getErrorCode();
|
||||
}
|
||||
public void RunTransformation(String transformName,
|
||||
int winHandler,
|
||||
String options,
|
||||
String projName,
|
||||
String folderName,
|
||||
String addOpts) throws Exception {
|
||||
Command("transformation:" + pack(transformName, options, projName, folderName, addOpts) + winHandler);
|
||||
}
|
||||
/*
|
||||
Модификации:
|
||||
SPF_ModifyArrayDistribution (addOpt1_c -> regId, addOpt2_c-> int64_t arrArrs, '|' as delimiter)
|
||||
SPF_InlineProcedure (addOpt1_c -> name | file, addOpt2_c-> line)
|
||||
*/
|
||||
public void RunModification(String modifyName, int winHandler, String options, String projName,
|
||||
String folderName, String addOpt1, String addOpt2) throws Exception {
|
||||
Command("modification:" + pack(modifyName, options, projName, folderName, addOpt1, addOpt2) + winHandler);
|
||||
}
|
||||
public void GetIntrinsics() throws Exception {
|
||||
Intrinsics.clear();
|
||||
if (RunAnalysis("SPF_GetIntrinsics", -1, "", "") >= 0) {
|
||||
String[] data = getResult().split(" ");
|
||||
Collections.addAll(Intrinsics, data);
|
||||
}
|
||||
}
|
||||
public boolean isIntrinsic(String func_name) {
|
||||
return Intrinsics.contains(func_name.toLowerCase());
|
||||
}
|
||||
//todo рефакторить. отвязать от текущего проекта.
|
||||
public void UpdateProjectFiles(boolean mode) throws Exception {
|
||||
ResetAllAnalyses();
|
||||
Current.getProject().dropLastModification();
|
||||
DBProjectFile cuf = null;
|
||||
if (Current.HasFile()) {
|
||||
cuf = Current.getFile();
|
||||
Pass_2021.passes.get(PassCode_2021.CloseCurrentFile).Do();
|
||||
}
|
||||
if (mode) //модификация
|
||||
{
|
||||
OldFiles.clear();
|
||||
for (String name : ModifiedFiles.keySet()) {
|
||||
if (Current.getProject().db.files.Data.containsKey(name)) {
|
||||
File file = Current.getProject().db.files.Data.get(name).file;
|
||||
OldFiles.put(name, Utils.ReadAllText(file));
|
||||
Utils.WriteToFile(file, ModifiedFiles.get(name));
|
||||
}
|
||||
}
|
||||
ModifiedFiles.clear();
|
||||
} else //откат.
|
||||
{
|
||||
if (OldFiles.size() > 0) {
|
||||
for (String name : OldFiles.keySet()) {
|
||||
File file = Current.getProject().db.files.Data.get(name).file;
|
||||
Utils.WriteToFile(file, OldFiles.get(name));
|
||||
}
|
||||
OldFiles.clear();
|
||||
} else CommonUI.Info("Сохранение файлов отсутствует.");
|
||||
}
|
||||
if (cuf != null)
|
||||
Pass_2021.passes.get(PassCode_2021.OpenCurrentFile).Do(cuf);
|
||||
}
|
||||
//</editor-fold>
|
||||
public Visual_DVM_2021.Passes.SapforAnalysis getAnalysisByPhase(String phase) {
|
||||
for (PassCode_2021 analysis_code : getAnalysesCodes()) {
|
||||
Visual_DVM_2021.Passes.SapforAnalysis analysis = (Visual_DVM_2021.Passes.SapforAnalysis) Pass_2021.passes.get(analysis_code);
|
||||
if (analysis.phase().equals(phase)) return analysis;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void ResetAllAnalyses() {
|
||||
for (PassCode_2021 code : getAnalysesCodes())
|
||||
(Pass_2021.passes.get(code)).Reset();
|
||||
//------------------------------------------------------------------------------------------>>>> пакетный режим.
|
||||
if (CommonUI.isActive()) {
|
||||
Pass_2021.passes.get(PassCode_2021.Precompilation).Reset();
|
||||
Pass_2021.passes.get(PassCode_2021.SPF_GetGCovInfo).Reset();
|
||||
}
|
||||
Global.enable_text_changed = false;
|
||||
Global.transformationPermission = TransformationPermission.None;
|
||||
if ((CommonUI.isActive()) && (UI.HasMainWindow()) && (UI.getVersionsWindow() != null))
|
||||
UI.getVersionsWindow().BlockVariants();
|
||||
}
|
||||
//--------------------------------------------------------------------------->>
|
||||
//временный (?) проход, по тихому получить размерность теста, предварительно выполнив тихий парс.
|
||||
//тут все одноразовое. считаем что таблицы бд уже заполнены как надо.
|
||||
public LanguageStyle getStyle() throws Exception {
|
||||
return ((GlobalDatabase)CommonUtils.db).settings.get(SettingName.FREE_FORM).toBoolean() ? LanguageStyle.free : LanguageStyle.fixed;
|
||||
}
|
||||
//----------
|
||||
public static Vector<PassCode_2021> getScenariosCodes() {
|
||||
Vector<PassCode_2021> res = new Vector<>();
|
||||
res.add(PassCode_2021.SPF_InitDeclsWithZero);//+
|
||||
res.add(PassCode_2021.SPF_ConvertStructures);//+
|
||||
res.add(PassCode_2021.SPF_ExpressionSubstitution);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_CreateCheckpoints); //+
|
||||
res.add(PassCode_2021.SPF_CreateIntervalsTree);//+
|
||||
res.add(PassCode_2021.SPF_RemoveDvmIntervals);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_RemoveDvmDirectives); //+
|
||||
res.add(PassCode_2021.SPF_RemoveDvmDirectivesToComments); //+
|
||||
|
||||
res.add(PassCode_2021.SPF_RemoveOmpDirectives);//+
|
||||
res.add(PassCode_2021.SPF_RemoveComments);//+
|
||||
res.add(PassCode_2021.SPF_RemoveDeadCode);//+
|
||||
res.add(PassCode_2021.SPF_RenameIncludes);
|
||||
res.add(PassCode_2021.SPF_InsertIncludesPass);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_LoopEndDoConverterPass); //+
|
||||
res.add(PassCode_2021.SPF_LoopUnion);//+
|
||||
res.add(PassCode_2021.SPF_LoopFission);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_PrivateShrinking);//+
|
||||
res.add(PassCode_2021.SPF_PrivateExpansion);//+
|
||||
res.add(PassCode_2021.SPF_PrivateRemoving);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_RemoveUnusedFunctions);//+
|
||||
res.add(PassCode_2021.SPF_DuplicateFunctionChains);//+
|
||||
//--
|
||||
res.add(PassCode_2021.SPF_ResolveParallelRegionConflicts);//+
|
||||
res.add(PassCode_2021.SPF_ResolveCommonBlockConflicts);//+
|
||||
//-
|
||||
res.add(PassCode_2021.SPF_InsertDvmhRegions);//+
|
||||
res.add(PassCode_2021.SPF_SharedMemoryParallelization);//+
|
||||
res.add(PassCode_2021.SPF_InsertImplicitNone);//+
|
||||
res.add(PassCode_2021.CreateParallelVariants); //?
|
||||
return res;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
public String getConsoleFlags() throws Exception {
|
||||
Vector<String> res = new Vector<>();
|
||||
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.FREE_FORM).toBoolean())
|
||||
res.add("-f90");
|
||||
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.STATIC_SHADOW_ANALYSIS).toBoolean())
|
||||
res.add("-sh");
|
||||
res.add("-shwidth " + ((GlobalDatabase)CommonUtils.db).settings.get(SettingName.MAX_SHADOW_WIDTH));
|
||||
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.KEEP_SPF_DIRECTIVES).toBoolean())
|
||||
res.add("-keepSPF");
|
||||
return String.join(" ", res);
|
||||
}
|
||||
public static boolean checkLines(Vector<String> lines) {
|
||||
for (String line : lines) {
|
||||
if (line.toLowerCase().contains("internal error")) {
|
||||
return false;
|
||||
}
|
||||
if (line.toLowerCase().contains("exception")) {
|
||||
return false;
|
||||
}
|
||||
if (line.contains("[ERROR]")) {
|
||||
return false;
|
||||
}
|
||||
if (line.toLowerCase().contains("segmentation fault")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//--
|
||||
public static boolean performScript(String name, //имя скрипта
|
||||
File sapfor_drv, //путь к сапфору
|
||||
File workspace, //проект
|
||||
String command, //проход
|
||||
String flags, //флаги
|
||||
String outName,
|
||||
String errName,
|
||||
Vector<String> resultLines
|
||||
) throws Exception {
|
||||
Process process = null;
|
||||
int exit_code = CommonConstants.Nan;
|
||||
//---
|
||||
File data_workspace = new File(workspace, Constants.data);
|
||||
Utils.CheckDirectory(data_workspace);
|
||||
File outputFile = new File(data_workspace, outName);
|
||||
File errorsFile = new File(data_workspace, errName);
|
||||
Utils.delete_with_check(outputFile);
|
||||
Utils.delete_with_check(errorsFile);
|
||||
//---
|
||||
File file = new File(data_workspace, name + (CommonUtils.isWindows() ? ".bat" : ".sh"));
|
||||
FileUtils.write(file,
|
||||
CommonUtils.DQuotes(sapfor_drv)
|
||||
+ (flags.isEmpty() ? "" : (" " + flags))
|
||||
+ " -noLogo"
|
||||
+ " " + command +
|
||||
" 1>" +
|
||||
CommonUtils.DQuotes(outputFile.getAbsolutePath()) +
|
||||
" 2>" +
|
||||
CommonUtils.DQuotes(errorsFile.getAbsolutePath()),
|
||||
Charset.defaultCharset());
|
||||
if (!file.setExecutable(true))
|
||||
throw new Exception("Не удалось сделать файл скрипта " + name + " исполняемым!");
|
||||
//--
|
||||
boolean flag = false;
|
||||
do {
|
||||
try {
|
||||
ProcessBuilder procBuilder = new ProcessBuilder(file.getAbsolutePath());
|
||||
procBuilder.directory(workspace);
|
||||
process = procBuilder.start();
|
||||
exit_code = process.waitFor();
|
||||
flag = true;
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
CommonUtils.sleep(1000);
|
||||
}
|
||||
}
|
||||
while (!flag);
|
||||
process = null;
|
||||
//---
|
||||
Vector<String> outputLines = new Vector<>(FileUtils.readLines(outputFile));
|
||||
Vector<String> errorsLines = new Vector<>(FileUtils.readLines(errorsFile));
|
||||
if (resultLines != null) {
|
||||
resultLines.addAll(outputLines);
|
||||
}
|
||||
return (exit_code == 0) &&
|
||||
checkLines(outputLines) &&
|
||||
checkLines(errorsLines);
|
||||
}
|
||||
public static boolean performScript(String name, //имя скрипта
|
||||
File sapfor_drv, //путь к сапфору
|
||||
File workspace, //проект
|
||||
String command, //проход
|
||||
String flags, //флаги
|
||||
String outName,
|
||||
String errName
|
||||
) throws Exception {
|
||||
return performScript(name, sapfor_drv, workspace, command, flags, outName, errName, null);
|
||||
}
|
||||
public static boolean parse(File sapfor_drv, File workspace, String flags) throws Exception {
|
||||
return performScript(
|
||||
"parse",
|
||||
sapfor_drv,
|
||||
workspace,
|
||||
"-parse -spf *.f* *.F*", // "-parse -spf *.f *.for *.fdv *.f90 *.f77",
|
||||
flags,
|
||||
Constants.parse_out_file,
|
||||
Constants.parse_err_file)
|
||||
&& (new File(workspace, "dvm.proj")).exists();
|
||||
}
|
||||
public static boolean analysis(File sapfor_drv, File workspace, PassCode_2021 code, String flags, Vector<String> result_lines) throws Exception {
|
||||
return performScript("analysis",
|
||||
sapfor_drv,
|
||||
workspace,
|
||||
code.getTestingCommand(),
|
||||
flags,
|
||||
Constants.out_file,
|
||||
Constants.err_file,
|
||||
result_lines
|
||||
);
|
||||
}
|
||||
public static File temp_copy = null;
|
||||
public static File getTempCopy(File src) throws Exception {
|
||||
if (temp_copy == null || !temp_copy.exists()) {
|
||||
temp_copy = Utils.getTempFileName("SAPFOR" + (CommonUtils.isWindows() ? ".exe" : ""));
|
||||
FileUtils.copyFile(src, temp_copy);
|
||||
temp_copy.setExecutable(true);
|
||||
}
|
||||
return temp_copy;
|
||||
}
|
||||
//--
|
||||
public static boolean getMinMaxDim(File sapfor_drv, File workspace, Test test) throws Exception {
|
||||
File sapfor = Sapfor.getTempCopy(sapfor_drv);
|
||||
String flags = "-noLogo";
|
||||
if (Sapfor.parse(sapfor, workspace, flags)
|
||||
) {
|
||||
Vector<String> outputLines = new Vector<>();
|
||||
if (Sapfor.analysis(sapfor, workspace, PassCode_2021.SPF_GetMaxMinBlockDistribution, flags, outputLines)) {
|
||||
//---
|
||||
for (String line : outputLines) {
|
||||
String prefix = "GET_MIN_MAX_BLOCK_DIST: ";
|
||||
if (line.startsWith(prefix)) {
|
||||
String s = line.substring(prefix.length());
|
||||
String[] data = s.split(" ");
|
||||
test.min_dim = Math.max(Integer.parseInt(data[0]), 0);
|
||||
test.max_dim = Math.max(Integer.parseInt(data[1]), 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static int readVersionFromCode(File versionFile) {
|
||||
int res = CommonConstants.Nan;
|
||||
if (versionFile.exists()) {
|
||||
try {
|
||||
List<String> data = FileUtils.readLines(versionFile);
|
||||
for (String s : data) {
|
||||
if (s.startsWith("#define VERSION_SPF ")) {
|
||||
String[] version_data = s.split("\"");
|
||||
if (version_data.length > 0) {
|
||||
String version_s = version_data[1];
|
||||
//-
|
||||
try {
|
||||
res = Integer.parseInt(version_s);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
32
src/_VisualDVM/Repository/Component/Sapfor/Sapfor_F.java
Normal file
32
src/_VisualDVM/Repository/Component/Sapfor/Sapfor_F.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Repository.Component.ComponentType;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
public class Sapfor_F extends Sapfor {
|
||||
@Override
|
||||
public ComponentType getComponentType() {
|
||||
return ComponentType.Sapfor_F;
|
||||
}
|
||||
@Override
|
||||
public String getAssemblyCommand() {
|
||||
return "cd Repo/sapfor/experts/Sapfor_2017/_bin\n" +
|
||||
"cmake ../\n" +
|
||||
"make -j 4\n";
|
||||
}
|
||||
@Override
|
||||
public File getAssemblyFile() {
|
||||
return Paths.get(
|
||||
Global.RepoDirectory.getAbsolutePath(),
|
||||
"sapfor/experts/Sapfor_2017/_bin/Sapfor_F").toFile();
|
||||
}
|
||||
@Override
|
||||
public String getUpdateCommand() {
|
||||
return "update_spf: ";
|
||||
}
|
||||
@Override
|
||||
public String getRestartCommand() {
|
||||
return "restart: ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package _VisualDVM.Repository.Component.Sapfor;
|
||||
public enum TransformationPermission {
|
||||
None,
|
||||
All,
|
||||
VariantsOnly
|
||||
}
|
||||
18
src/_VisualDVM/Repository/Component/UI/ComponentsFields.form
Normal file
18
src/_VisualDVM/Repository/Component/UI/ComponentsFields.form
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.Repository.Component.UI.ComponentsFields">
|
||||
<grid id="27dc6" binding="content" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="802" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="a969b" binding="componentsPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
17
src/_VisualDVM/Repository/Component/UI/ComponentsFields.java
Normal file
17
src/_VisualDVM/Repository/Component/UI/ComponentsFields.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package _VisualDVM.Repository.Component.UI;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class ComponentsFields implements DialogFields {
|
||||
public JPanel content;
|
||||
private JPanel componentsPanel;
|
||||
public ComponentsFields() {
|
||||
Global.Components.mountUI(componentsPanel);
|
||||
}
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
44
src/_VisualDVM/Repository/Component/UI/ComponentsForm.java
Normal file
44
src/_VisualDVM/Repository/Component/UI/ComponentsForm.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package _VisualDVM.Repository.Component.UI;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Visual.Windows.Dialog.Dialog;
|
||||
|
||||
import java.awt.*;
|
||||
public class ComponentsForm extends Dialog<Object, ComponentsFields> {
|
||||
public ComponentsForm() {
|
||||
super(ComponentsFields.class);
|
||||
}
|
||||
@Override
|
||||
public boolean NeedsScroll() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return Global.properties.ComponentsWindowWidth;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return Global.properties.ComponentsWindowHeight;
|
||||
}
|
||||
@Override
|
||||
public void CreateButtons() {
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
Global.Components.ShowUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void LoadSize() {
|
||||
setMinimumSize(new Dimension(650, 250));
|
||||
Dimension dimension = new Dimension(getDefaultWidth(), getDefaultHeight());
|
||||
setPreferredSize(dimension);
|
||||
setSize(dimension);
|
||||
}
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
Global.properties.ComponentsWindowWidth=getWidth();
|
||||
Global.properties.ComponentsWindowHeight=getHeight();
|
||||
Global.properties.Update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.Repository.Component.UI.PickUpComponentFields">
|
||||
<grid id="27dc6" binding="content" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,12 @@
|
||||
package _VisualDVM.Repository.Component.UI;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class PickUpComponentFields implements DialogFields {
|
||||
private JPanel content;
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
126
src/_VisualDVM/Repository/Component/UI/PublishFields.form
Normal file
126
src/_VisualDVM/Repository/Component/UI/PublishFields.form
Normal file
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.Repository.Component.UI.PublishFields">
|
||||
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="16"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8edb0" class="javax.swing.JCheckBox" binding="cbNeedsBroadcast">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="0"/>
|
||||
<selected value="true"/>
|
||||
<text value="Включить оповещение о публикации"/>
|
||||
<verticalAlignment value="3"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="b33e5">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="326bc" class="javax.swing.JTextArea" binding="taBroadcast" custom-create="true">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<lineWrap value="true"/>
|
||||
<wrapStyleWord value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="fbdf3" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="текст оповещения"/>
|
||||
<verticalAlignment value="3"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="21340" class="javax.swing.JCheckBox" binding="cbForceMail">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="0"/>
|
||||
<selected value="false"/>
|
||||
<text value="Разослать файл всем подписчикам"/>
|
||||
<verticalAlignment value="3"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="148fa" class="javax.swing.JCheckBox" binding="cbUpdateMinimalVersion">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="0"/>
|
||||
<selected value="true"/>
|
||||
<text value="Назначить минимальную версию"/>
|
||||
<verticalAlignment value="3"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b1e6f" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="0"/>
|
||||
<text value="Минимальная версия: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7e269" class="javax.swing.JLabel" binding="lMinimalVersion">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="1"/>
|
||||
<text value="?"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="37705">
|
||||
<constraints>
|
||||
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="128e5" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="0"/>
|
||||
<text value="Публикуемая версия: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="84e2b" class="javax.swing.JLabel" binding="lPublishingVersion">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="1"/>
|
||||
<text value="?"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b01cb" class="javax.swing.JCheckBox" binding="cbAssemblyOnServer">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="0"/>
|
||||
<selected value="true"/>
|
||||
<text value="Собрать на сервере"/>
|
||||
<verticalAlignment value="3"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
35
src/_VisualDVM/Repository/Component/UI/PublishFields.java
Normal file
35
src/_VisualDVM/Repository/Component/UI/PublishFields.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package _VisualDVM.Repository.Component.UI;
|
||||
import _VisualDVM.Visual.Editor.BaseEditor;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
public class PublishFields implements DialogFields {
|
||||
public JPanel content;
|
||||
public JCheckBox cbNeedsBroadcast;
|
||||
public JTextArea taBroadcast;
|
||||
public JCheckBox cbForceMail;
|
||||
public JCheckBox cbUpdateMinimalVersion;
|
||||
public JLabel lMinimalVersion;
|
||||
public JLabel lPublishingVersion;
|
||||
public JCheckBox cbAssemblyOnServer;
|
||||
public PublishFields() {
|
||||
cbNeedsBroadcast.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
taBroadcast.setEnabled(cbNeedsBroadcast.isSelected());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void createUIComponents() {
|
||||
// TODO: place custom component creation code here
|
||||
taBroadcast = new BaseEditor();
|
||||
}
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
}
|
||||
16
src/_VisualDVM/Repository/Component/UI/PublishForm.java
Normal file
16
src/_VisualDVM/Repository/Component/UI/PublishForm.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package _VisualDVM.Repository.Component.UI;
|
||||
import Common.Visual.Windows.Dialog.Dialog;
|
||||
public class PublishForm extends Dialog<String, PublishFields> {
|
||||
public PublishForm() {
|
||||
super(PublishFields.class);
|
||||
}
|
||||
@Override
|
||||
public boolean NeedsScroll() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result = fields.cbNeedsBroadcast.isSelected() ? fields.taBroadcast.getText() : null;
|
||||
}
|
||||
|
||||
}
|
||||
89
src/_VisualDVM/Repository/Component/Visualiser.java
Normal file
89
src/_VisualDVM/Repository/Component/Visualiser.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.GlobalData.GlobalDatabase;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Settings.SettingName;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
public class Visualiser extends Component {
|
||||
//-----------------------------------------
|
||||
private static Date getClassBuildTime() {
|
||||
Date d = null;
|
||||
Class<?> currentClass = new Object() {
|
||||
}.getClass().getEnclosingClass();
|
||||
URL resource = currentClass.getResource(currentClass.getSimpleName() + ".class");
|
||||
if (resource != null) {
|
||||
if (resource.getProtocol().equals("file")) {
|
||||
try {
|
||||
d = new Date(new File(resource.toURI()).lastModified());
|
||||
} catch (URISyntaxException ignored) {
|
||||
}
|
||||
} else if (resource.getProtocol().equals("jar")) {
|
||||
String path = resource.getPath();
|
||||
d = new Date(new File(path.substring(5, path.indexOf("!"))).lastModified());
|
||||
} else if (resource.getProtocol().equals("zip")) {
|
||||
String path = resource.getPath();
|
||||
File jarFileOnDisk = new File(path.substring(0, path.indexOf("!")));
|
||||
try (JarFile jf = new JarFile(jarFileOnDisk)) {
|
||||
ZipEntry ze = jf.getEntry(path.substring(path.indexOf("!") + 2));
|
||||
long zeTimeLong = ze.getTime();
|
||||
Date zeTimeDate = new Date(zeTimeLong);
|
||||
d = zeTimeDate;
|
||||
} catch (IOException | RuntimeException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "VisualSapfor.jar";
|
||||
}
|
||||
@Override
|
||||
public String getNewFileName() {
|
||||
return "VisualSapfor_new.jar";
|
||||
}
|
||||
@Override
|
||||
public ComponentType getComponentType() {
|
||||
return ComponentType.Visualiser;
|
||||
}
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Методы">
|
||||
//</editor-// fold>
|
||||
//http://www.seostella.com/ru/article/2012/02/05/formatirovanie-daty-v-java.html
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
version = 1115;
|
||||
String pattern = "MMM dd yyyy HH:mm:ss";
|
||||
DateFormat df = new SimpleDateFormat(pattern, Locale.ENGLISH);
|
||||
date_text = df.format(getClassBuildTime());
|
||||
}
|
||||
@Override
|
||||
public void Update() throws Exception {
|
||||
super.Update();
|
||||
Global.visualizer_2.SendRequest("update: ");
|
||||
System.exit(0);
|
||||
}
|
||||
public File getWorkspace() {
|
||||
if (!((GlobalDatabase)CommonUtils.db).settings.get(SettingName.Workspace).toString().isEmpty()) {
|
||||
File workspace = new File(((GlobalDatabase)CommonUtils.db).settings.get(SettingName.Workspace).toString());
|
||||
if (workspace.exists())
|
||||
return workspace;
|
||||
else
|
||||
Pass_2021.passes.get(PassCode_2021.UpdateSetting).Do(
|
||||
SettingName.Workspace, "");
|
||||
}
|
||||
return Global.ProjectsDirectory;
|
||||
}
|
||||
}
|
||||
133
src/_VisualDVM/Repository/Component/Visualizer_2.java
Normal file
133
src/_VisualDVM/Repository/Component/Visualizer_2.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package _VisualDVM.Repository.Component;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Utils;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.nio.file.Paths;
|
||||
public class Visualizer_2 extends OSDComponent {
|
||||
//</editor-fold>
|
||||
//-
|
||||
//<editor-fold desc="функционал">
|
||||
int port;
|
||||
public String PID = "";
|
||||
Socket client = null;
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
String request = "";
|
||||
String response = "";
|
||||
public Visualizer_2(int port_in) {
|
||||
port = port_in;
|
||||
}
|
||||
public static void UnpackVersionInfo(Component component, String packed) {
|
||||
String[] data = packed.split("\\|");
|
||||
//лишний пробел.
|
||||
String text = data[0].substring(0, data[0].length() - 1);
|
||||
component.date_text = data[1] + data[2] + data[3];
|
||||
component.version = Long.parseLong(text);
|
||||
}
|
||||
//<editor-fold desc="компонент">
|
||||
@Override
|
||||
public ComponentType getComponentType() {
|
||||
return ComponentType.Visualizer_2;
|
||||
}
|
||||
@Override
|
||||
public String getHome() {
|
||||
return CommonUtils.getHomePath();
|
||||
}
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
Command("get_version: ");
|
||||
UnpackVersionInfo(this, response);
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
public void refreshPid(){
|
||||
try {
|
||||
// UI.Info("Getting Server PID...");
|
||||
Command("get_pid: ");
|
||||
PID = response;
|
||||
// UI.Info("SERVER PID = "+Utils.Brackets(PID));
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void Update() throws Exception {
|
||||
super.Update();
|
||||
SendRequest("update_server: ");
|
||||
ReplaceOldFile();
|
||||
CommonUI.Info("Сервер успешно обновлен.\n" +
|
||||
"Визуализатор завершает работу.\n" +
|
||||
"Для продолжения перезапустите визуализатор вручную.");
|
||||
System.exit(0);
|
||||
}
|
||||
@Override
|
||||
public String getAssemblyCommand() {
|
||||
return "cd Repo/sapfor/experts/Sapfor_2017/_src/Server\n" +
|
||||
"g++ -O3 -std=c++17 checkUniq.cpp server.cpp -o Visualizer_2 -lpthread -lstdc++fs\n";
|
||||
}
|
||||
@Override
|
||||
public File getAssemblyFile() {
|
||||
return Paths.get(
|
||||
Global.RepoDirectory.getAbsolutePath(),
|
||||
"sapfor/experts/Sapfor_2017/_src/Server/Visualizer_2").toFile();
|
||||
}
|
||||
public void Connect() throws Exception {
|
||||
ClearLog();
|
||||
Print("соединение с Visualiser_2...");
|
||||
client = Utils.createClientSocket(
|
||||
InetAddress.getLoopbackAddress(),
|
||||
port, 0
|
||||
);
|
||||
in = new BufferedReader(new InputStreamReader(client.getInputStream())); //то что нам приходит от сервера
|
||||
out = new PrintWriter(client.getOutputStream(), true); //то что мы пишем серверу.
|
||||
}
|
||||
public void Interrupt(){
|
||||
Utils.Kill(PID, false);
|
||||
}
|
||||
public void Shutdown() throws Exception {
|
||||
Print("завершение сеанса с Visualiser_2...");
|
||||
SendRequest("close: ");
|
||||
if (client != null)
|
||||
client.close();
|
||||
if (in != null)
|
||||
in.close();
|
||||
if (out != null)
|
||||
out.close();
|
||||
}
|
||||
//запрос.
|
||||
public void SendRequest(String request_in) throws Exception {
|
||||
Print("->" + request_in);
|
||||
out.flush();
|
||||
System.gc();
|
||||
out.println(request = request_in);
|
||||
}
|
||||
//запрос-ответ. анализируются только общие ошибочные случаи.
|
||||
public String Command(String request_in) throws Exception {
|
||||
SendRequest(request_in);
|
||||
response = in.readLine();
|
||||
switch (response) {
|
||||
case "NOT_FOUND":
|
||||
case "WRONG":
|
||||
case "SEG_FAULT":
|
||||
throw new PassException("Команда серверу SAPFOR вернула " + CommonUtils.Brackets(response));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Print("<-" + response);
|
||||
out.flush();
|
||||
System.gc();
|
||||
return response;
|
||||
}
|
||||
//</editor-fold>
|
||||
}
|
||||
23
src/_VisualDVM/Repository/EmailMessage.java
Normal file
23
src/_VisualDVM/Repository/EmailMessage.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package _VisualDVM.Repository;
|
||||
import Common.Utils.CommonUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public class EmailMessage implements Serializable {
|
||||
public String subject = ""; //тема письма
|
||||
public String text = ""; //текст письма
|
||||
public Vector<String> targets = new Vector<>(); //адресаты
|
||||
public LinkedHashMap<String, byte[]> files = new LinkedHashMap<>(); //вложения.
|
||||
public EmailMessage() {
|
||||
}
|
||||
public EmailMessage(String subject_in, String text_in, Vector<String> targets_in) {
|
||||
subject = subject_in;
|
||||
text = text_in;
|
||||
targets.addAll(targets_in);
|
||||
}
|
||||
public void addAttachement(File f) throws Exception {
|
||||
files.put(f.getName(), CommonUtils.fileToBytes(f));
|
||||
}
|
||||
}
|
||||
74
src/_VisualDVM/Repository/RepositoryClient.java
Normal file
74
src/_VisualDVM/Repository/RepositoryClient.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package _VisualDVM.Repository;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Repository.Server.ServerCode;
|
||||
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
public abstract class RepositoryClient {
|
||||
//--
|
||||
protected int getSleepMillis() {
|
||||
return 2000;
|
||||
}
|
||||
//---
|
||||
protected boolean isPrintOn() {
|
||||
return true;
|
||||
}
|
||||
protected void Print(String message) {
|
||||
try {
|
||||
if (isPrintOn()) {
|
||||
FileWriter testLog = new FileWriter(getClass().getSimpleName() + "_Log.txt", true);
|
||||
String dmessage = CommonUtils.Brackets(new Date()) + " " + message;
|
||||
System.out.println(dmessage);
|
||||
testLog.write(dmessage + "\n");
|
||||
testLog.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
//--
|
||||
protected Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
|
||||
TestingSystemPass<Object> pass = new TestingSystemPass<Object>() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
protected void ServerAction() throws Exception {
|
||||
Command(new ServerExchangeUnit_2021(code_in, arg, object_in));
|
||||
target = response.object;
|
||||
}
|
||||
@Override
|
||||
protected boolean validate() {
|
||||
return Log.isEmpty();
|
||||
}
|
||||
};
|
||||
if (!pass.Do()) {
|
||||
ServerConnectionError(code_in, pass.Log.toString());
|
||||
}
|
||||
return pass.target;
|
||||
}
|
||||
protected Object ServerCommand(ServerCode code_in, Serializable object_in) throws Exception {
|
||||
return ServerCommand(code_in, "", object_in);
|
||||
}
|
||||
protected Object ServerCommand(ServerCode code_in) throws Exception {
|
||||
return ServerCommand(code_in, "", null);
|
||||
}
|
||||
protected void ServerConnectionError(ServerCode code_in, String logText) throws Exception {
|
||||
throw new PassException(CommonUtils.Brackets(new Date().toString())+" Ошибка взаимодействия с сервером " + code_in);
|
||||
}
|
||||
public abstract void perform() throws Exception;
|
||||
public void Perform(){
|
||||
try {
|
||||
perform();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
CommonUtils.sleep(getSleepMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/_VisualDVM/Repository/RepositoryRefuseException.java
Normal file
7
src/_VisualDVM/Repository/RepositoryRefuseException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package _VisualDVM.Repository;
|
||||
public class RepositoryRefuseException extends Exception{
|
||||
//исключение для "штатных" отказов. например отсутствие объекта с заданным ключом.
|
||||
public RepositoryRefuseException(String message_in){
|
||||
super(message_in);
|
||||
}
|
||||
}
|
||||
379
src/_VisualDVM/Repository/RepositoryServer.java
Normal file
379
src/_VisualDVM/Repository/RepositoryServer.java
Normal file
@@ -0,0 +1,379 @@
|
||||
package _VisualDVM.Repository;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Constants;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Database;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Utils.InterruptThread;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.Repository.Server.DiagnosticSignalHandler;
|
||||
import _VisualDVM.Repository.Server.ServerCode;
|
||||
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
|
||||
import javafx.util.Pair;
|
||||
import sun.misc.SignalHandler;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
public abstract class RepositoryServer<D extends Database> {
|
||||
Class<D> d_class;
|
||||
protected Socket clientSocket; //сокет для общения
|
||||
protected ServerSocket server; // серверсокет
|
||||
protected ObjectInputStream in; // поток чтения из сокета
|
||||
protected ObjectOutputStream out; // поток записи в сокет
|
||||
//-
|
||||
public D db;
|
||||
protected static FileWriter Log;
|
||||
protected ServerExchangeUnit_2021 request;
|
||||
protected ServerExchangeUnit_2021 response;
|
||||
//-
|
||||
protected ServerCode code;
|
||||
protected long count = 0; //для отладки.
|
||||
protected static boolean printOn = false;
|
||||
//-----------
|
||||
SignalHandler signalHandler = signal -> {
|
||||
};
|
||||
//------------
|
||||
public abstract int getPort();
|
||||
protected abstract void Session() throws Exception;
|
||||
protected void startAdditionalThreads() {
|
||||
}
|
||||
public final static String separator = "----------------------------------";
|
||||
public RepositoryServer(Class<D> d_class_in) {
|
||||
d_class = d_class_in;
|
||||
}
|
||||
public void ActivateDB() {
|
||||
try {
|
||||
db = d_class.newInstance();
|
||||
db.Connect();
|
||||
db.CreateAllTables();
|
||||
db.prepareTablesStatements();
|
||||
db.Synchronize();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
protected Thread interruptThread = new InterruptThread(10000,
|
||||
() -> {
|
||||
System.exit(0);
|
||||
return null;
|
||||
});
|
||||
protected static void Print(String message) {
|
||||
if (printOn) {
|
||||
try {
|
||||
Log = new FileWriter("Log.txt", true);
|
||||
String dmessage = CommonUtils.Brackets("SESSION -> ") + new Date() +
|
||||
" " + message;
|
||||
Log.write(dmessage + "\n");
|
||||
Log.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void checkTargets(EmailMessage message_in) {
|
||||
}
|
||||
public void Email(EmailMessage message_in, File... directAttachements) throws Exception {
|
||||
checkTargets(message_in);
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.host", Global.properties.SMTPHost);
|
||||
props.put("mail.smtp.auth", "true");
|
||||
props.put("mail.smtp.port", String.valueOf(Global.properties.SMTPPort));
|
||||
props.put("mail.smtp.socketFactory.port", String.valueOf(Global.properties.MailSocketPort));
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
props.put("mail.smtp.connectiontimeout", String.valueOf(Global.properties.SocketTimeout));
|
||||
props.put("mail.smtp.timeout", String.valueOf(Global.properties.SocketTimeout));
|
||||
props.put("mail.smtp.writetimeout", String.valueOf(Global.properties.SocketTimeout));
|
||||
//------------------------------
|
||||
LinkedHashMap<String, File> innerFiles = new LinkedHashMap<>();
|
||||
for (String aName : message_in.files.keySet()) {
|
||||
File f = Utils.getTempFileName(aName);
|
||||
CommonUtils.bytesToFile(message_in.files.get(aName), f);
|
||||
innerFiles.put(aName, f);
|
||||
}
|
||||
Vector<String> targets_ = new Vector<>(message_in.targets);
|
||||
Utils.addDefaultMails(targets_);
|
||||
//------------------------------
|
||||
Session session = Session.getDefaultInstance(props,
|
||||
new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(
|
||||
Constants.MailAddress,
|
||||
Constants.MailPassword);
|
||||
}
|
||||
});
|
||||
|
||||
for (String target : targets_) {
|
||||
boolean done = false;
|
||||
int attempts = 5;
|
||||
while (!done && (attempts > 0)) {
|
||||
try {
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(Constants.MailAddress));
|
||||
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(target));
|
||||
message.setSubject(message_in.subject);
|
||||
Multipart multipart = new MimeMultipart();
|
||||
MimeBodyPart textBodyPart = new MimeBodyPart();
|
||||
textBodyPart.setText(message_in.text);
|
||||
multipart.addBodyPart(textBodyPart);
|
||||
for (String aName : innerFiles.keySet()) {
|
||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||
DataSource source = new FileDataSource(innerFiles.get(aName));
|
||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||
attachmentBodyPart.setFileName(aName);
|
||||
multipart.addBodyPart(attachmentBodyPart);
|
||||
}
|
||||
for (File f : directAttachements) {
|
||||
if (f.exists()) {
|
||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||
DataSource source = new FileDataSource(f);
|
||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||
attachmentBodyPart.setFileName(f.getName());
|
||||
multipart.addBodyPart(attachmentBodyPart);
|
||||
}
|
||||
}
|
||||
message.setContent(multipart);
|
||||
Transport.send(message);
|
||||
done = true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Исключение во время отправки сообщения абоненту " + CommonUtils.Brackets(target));
|
||||
ex.printStackTrace();
|
||||
CommonUtils.sleep(1000);
|
||||
} finally {
|
||||
attempts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Исключение во время выполнения рассылки.");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
public boolean canDelete(DBObject object) throws Exception {
|
||||
return true;
|
||||
}
|
||||
public void StartAction() throws Exception {
|
||||
}
|
||||
public void Start() throws Exception {
|
||||
/*
|
||||
File started = new File(Constants.STARTED);
|
||||
if (started.exists())
|
||||
FileUtils.forceDelete(started);
|
||||
Utils.createEmptyFile(Constants.STARTED);
|
||||
*/
|
||||
DiagnosticSignalHandler.install("TERM", signalHandler);
|
||||
DiagnosticSignalHandler.install("INT", signalHandler);
|
||||
DiagnosticSignalHandler.install("ABRT", signalHandler);
|
||||
interruptThread.start();
|
||||
startAdditionalThreads();
|
||||
server = new ServerSocket(getPort());
|
||||
Print("Сервер запущен!");
|
||||
StartAction();
|
||||
while (true) {
|
||||
try {
|
||||
clientSocket = server.accept();
|
||||
Print((count++) + " клиент присоединился, IP=" + clientSocket.getInetAddress());
|
||||
code = ServerCode.Undefined;
|
||||
out = new ObjectOutputStream(clientSocket.getOutputStream());
|
||||
in = new ObjectInputStream(clientSocket.getInputStream());
|
||||
//->
|
||||
while (true) {
|
||||
DBObject dbObject = null;
|
||||
Pair<Class, Object> p = null;
|
||||
Print("Ожидание команды от клиента...");
|
||||
Object transport = in.readObject();
|
||||
Print("Команда прочитана.");
|
||||
if (transport instanceof ServerExchangeUnit_2021) {
|
||||
request = (ServerExchangeUnit_2021) transport;
|
||||
response = null;
|
||||
Print("клиент_2021: <- " + (request.codeName));
|
||||
try {
|
||||
code = request.getCode();
|
||||
//базовый функционал.
|
||||
switch (code) {
|
||||
//<editor-fold desc="файлы и почта">
|
||||
case ReadFile:
|
||||
Print("Отправить клиенту текст файла по пути " + CommonUtils.Brackets(request.arg));
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK, "", Utils.ReadAllText(new File(request.arg)));
|
||||
break;
|
||||
case SendFile:
|
||||
//нам пришел файл.
|
||||
Print("Получить от клиента файл, и распаковать его по пути " + CommonUtils.Brackets(request.arg));
|
||||
request.Unpack(); //распаковка идет по его аргу-пути назначения
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case ReceiveFile:
|
||||
Print("Отправить клиенту файл по пути " + CommonUtils.Brackets(request.arg));
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
File file = new File(request.arg);
|
||||
response.object = file.exists() ? CommonUtils.fileToBytes(file) : null;
|
||||
break;
|
||||
case Email:
|
||||
Print("Отправка сообщения электронной почты");
|
||||
Email((EmailMessage) request.object);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Главная база данных">
|
||||
case CheckObjectExistense:
|
||||
p = (Pair<Class, Object>) request.object;
|
||||
Print("Проверить существование объекта класса " + p.getKey().toString() + " с ключом " + p.getValue());
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = db.checkObjectExistense(p.getKey(), p.getValue());
|
||||
break;
|
||||
case EditObject:
|
||||
DBObject new_object = (DBObject) request.object;
|
||||
Print("Редактировать объект " + new_object.getPK());
|
||||
db.UpdateWithCheck(new_object);
|
||||
afterEditAction(new_object);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case DeleteObject: //устарело. потом убрать. сейчас на это баг репорты повязаны.
|
||||
dbObject = (DBObject) request.object;
|
||||
Print("Удалить объект " + dbObject.getPK());
|
||||
db.DeleteWithCheck(dbObject);
|
||||
afterDeleteAction(dbObject);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case GetObjectCopyByPK:
|
||||
p = (Pair<Class, Object>) request.object;
|
||||
Print("Получить копию объекта класса " + p.getKey().toString() + " по ключу " + p.getValue());
|
||||
dbObject = db.getObjectCopyByPK(p.getKey(), p.getValue());
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = dbObject;
|
||||
break;
|
||||
case GetObjectsCopiesByPK:
|
||||
Print("Получить список копий объектов по ключам");
|
||||
p = (Pair<Class, Object>) request.object;
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = db.getObjectsCopies(p.getKey(), (Vector<Object>) p.getValue());
|
||||
break;
|
||||
case PublishObject:
|
||||
PublishObject();
|
||||
break;
|
||||
case PublishObjects:
|
||||
PublishObjects();
|
||||
break;
|
||||
case DeleteObjectByPK:
|
||||
DeleteObjectByPK();
|
||||
break;
|
||||
case DeleteObjectsByPK:
|
||||
DeleteObjectsByPK();
|
||||
break;
|
||||
//</editor-fold>
|
||||
case EXIT:
|
||||
Print("ЗАВЕРШИТЬ РАБОТУ СЕРВЕРА");
|
||||
System.exit(0);
|
||||
break;
|
||||
case Ping:
|
||||
Print("Проверка активности сервера");
|
||||
Ping();
|
||||
break;
|
||||
default:
|
||||
Session();
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.FAIL, "Исключение сервера", ex);
|
||||
} finally {
|
||||
Print("сервер: -> " + response.codeName);
|
||||
out.writeObject(response);
|
||||
Print("Ответ отправлен.");
|
||||
}
|
||||
}
|
||||
}
|
||||
//->
|
||||
} catch (Exception ex) {
|
||||
Print("Соединение с клиентом завершено.");
|
||||
} finally {
|
||||
//->
|
||||
try {
|
||||
if (clientSocket != null)
|
||||
clientSocket.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// потоки тоже хорошо бы закрыть
|
||||
try {
|
||||
if (in != null)
|
||||
in.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (out != null)
|
||||
out.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
Print("Сервер ждет следующего клиента.");
|
||||
}
|
||||
}
|
||||
}
|
||||
//--
|
||||
protected Database getDefaultDatabase() {
|
||||
return db;
|
||||
}
|
||||
//--
|
||||
private void PublishObject() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
DBObject dbObject = (DBObject) request.object;
|
||||
beforePublishAction(dbObject);
|
||||
response.object = (Serializable) getDefaultDatabase().InsertS(dbObject).getPK();
|
||||
afterPublishAction(dbObject);
|
||||
}
|
||||
private void PublishObjects() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
Vector<DBObject> objects = (Vector<DBObject>) request.object;
|
||||
Database database = getDefaultDatabase();
|
||||
for (DBObject dbObject : objects) {
|
||||
beforePublishAction(dbObject);
|
||||
response.object = (Serializable) database.InsertS(dbObject).getPK();
|
||||
afterPublishAction(dbObject);
|
||||
}
|
||||
}
|
||||
protected void beforePublishAction(DBObject object) throws Exception {
|
||||
}
|
||||
protected void afterPublishAction(DBObject object) throws Exception {
|
||||
}
|
||||
protected void afterEditAction(DBObject object) throws Exception {
|
||||
}
|
||||
//------------------------------
|
||||
private void DeleteObjectByPK() throws Exception {
|
||||
Print("Удалить объект по ключу");
|
||||
Pair<Class, Object> to_delete = (Pair<Class, Object>) request.object;
|
||||
afterDeleteAction(getDefaultDatabase().DeleteByPK(to_delete.getKey(), to_delete.getValue()));
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
}
|
||||
private void DeleteObjectsByPK() throws Exception {
|
||||
Print("Удалить объекты по ключам");
|
||||
Pair<Class, Vector<Object>> to_delete = (Pair<Class, Vector<Object>>) request.object;
|
||||
Database database = getDefaultDatabase();
|
||||
for (Object object : to_delete.getValue()) {
|
||||
afterDeleteAction(database.DeleteByPK(to_delete.getKey(), object));
|
||||
}
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
}
|
||||
public void afterDeleteAction(DBObject object) throws Exception {
|
||||
}
|
||||
public void Ping() {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
}
|
||||
}
|
||||
424
src/_VisualDVM/Repository/Server/ComponentsServer.java
Normal file
424
src/_VisualDVM/Repository/Server/ComponentsServer.java
Normal file
@@ -0,0 +1,424 @@
|
||||
package _VisualDVM.Repository.Server;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.GlobalData.Account.Account;
|
||||
import _VisualDVM.GlobalData.Machine.Machine;
|
||||
import _VisualDVM.GlobalData.Machine.MachineType;
|
||||
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
|
||||
import _VisualDVM.GlobalData.User.User;
|
||||
import _VisualDVM.ProjectData.LanguageName;
|
||||
import _VisualDVM.Repository.BugReport.BugReport;
|
||||
import _VisualDVM.Repository.BugReport.BugReportInterface;
|
||||
import _VisualDVM.Repository.BugReportsDatabase;
|
||||
import _VisualDVM.Repository.Component.ComponentType;
|
||||
import _VisualDVM.Repository.EmailMessage;
|
||||
import _VisualDVM.Repository.RepositoryRefuseException;
|
||||
import _VisualDVM.Repository.RepositoryServer;
|
||||
import _VisualDVM.Repository.Subscribes.Subscriber;
|
||||
import Visual_DVM_2021.Passes.All.ArchivesBackupPass;
|
||||
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
|
||||
import Visual_DVM_2021.Passes.All.ZipFolderPass;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
public static final String server_dvm_drv = "/home/DVM/dvm_current/dvm_sys/bin/dvm_drv";
|
||||
public ComponentsServer() {
|
||||
super(BugReportsDatabase.class);
|
||||
}
|
||||
@Override
|
||||
public int getPort() {
|
||||
return Global.properties.ComponentsServerPort;
|
||||
}
|
||||
@Override
|
||||
protected void checkTargets(EmailMessage message_in) {
|
||||
Vector<String> checkedTargets = new Vector<>();
|
||||
for (String email: message_in.targets){
|
||||
if (db.subscribers.containsKey(email)){
|
||||
Subscriber subscriber = db.subscribers.get(email);
|
||||
if (subscriber.mailOn>0){
|
||||
checkedTargets.add(email);
|
||||
}
|
||||
}else checkedTargets.add(email); //если почта не зарегана значит это мейл с регистрацией.
|
||||
}
|
||||
message_in.targets = checkedTargets;
|
||||
}
|
||||
@Override
|
||||
public void afterDeleteAction(DBObject object) throws Exception {
|
||||
if (object instanceof BugReport) {
|
||||
BugReport bugReport = (BugReport) object;
|
||||
if (!bugReport.project_version.isEmpty())
|
||||
Utils.delete_with_check(BugReportInterface.getArchiveFile(bugReport));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void StartAction() throws Exception {
|
||||
if (Global.properties.EmailAdminsOnStart) {
|
||||
EmailMessage message = new EmailMessage(
|
||||
"Сервер Sapfor запущен",
|
||||
new Date().toString(),
|
||||
new Vector<>()
|
||||
);
|
||||
Email(message);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void Session() throws Exception {
|
||||
BugReport bugReport = null;
|
||||
Subscriber subscriber = null;
|
||||
Account account = null;
|
||||
if (!Global.properties.OldServer) {
|
||||
switch (code) {
|
||||
//<editor-fold desc="Регистрация">
|
||||
case CheckSubscriberRole:
|
||||
Print("Проверить роль пользователя");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
account = (Account) request.object;
|
||||
if (db.subscribers.containsKey(account.email)) {
|
||||
subscriber = db.subscribers.get(account.email);
|
||||
} else {
|
||||
subscriber = new Subscriber();
|
||||
subscriber.name = account.name;
|
||||
subscriber.address = account.email;
|
||||
subscriber.mailOn = 1;
|
||||
db.Insert(subscriber);
|
||||
}
|
||||
response.object = subscriber; //возвращаем информацию о подписчике.
|
||||
break;
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="БАГ РЕПОРТЫ">
|
||||
case ReceiveAllArchives:
|
||||
Print("Отправить клиенту архив всех архивов баг репортов");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
File archives = new File(CommonUtils.getDateName("Bugs"));
|
||||
if (zip.Do("Bugs", archives.getAbsolutePath())) {
|
||||
response.object = CommonUtils.fileToBytes(archives);
|
||||
Print("Архив успешно запакован");
|
||||
} else throw new RepositoryRefuseException("Не удалось запаковать архивы");
|
||||
break;
|
||||
case UpdateBugReport:
|
||||
//-
|
||||
BugReport oldBugReport = (BugReport) request.object;
|
||||
Print("Обновить баг репорт " + oldBugReport.id);
|
||||
if (db.bugReports.containsKey(oldBugReport.id)) {
|
||||
bugReport = db.bugReports.get(oldBugReport.id);
|
||||
bugReport.SynchronizeFields(oldBugReport);
|
||||
bugReport.change_date = oldBugReport.change_date;
|
||||
db.Update(bugReport);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + oldBugReport.id + " не существует.");
|
||||
break;
|
||||
case UpdateBugReportField: //нужно для дополнений полей
|
||||
//-
|
||||
BugReport oldBugReport_ = (BugReport) request.object;
|
||||
Print("Обновить поле " + request.arg + " баг репорта " + oldBugReport_.id);
|
||||
if (db.bugReports.containsKey(oldBugReport_.id)) {
|
||||
bugReport = db.bugReports.get(oldBugReport_.id);
|
||||
Object newValue = BugReport.class.getField(request.arg).get(oldBugReport_);
|
||||
BugReport.class.getField(request.arg).set(bugReport, newValue);
|
||||
bugReport.change_date = oldBugReport_.change_date;
|
||||
db.Update(bugReport);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + oldBugReport_.id + " не существует.");
|
||||
break;
|
||||
case ReceiveBugReportsDatabase:
|
||||
Print("Получить базу данных баг репортов");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = CommonUtils.fileToBytes(db.getFile());
|
||||
break;
|
||||
case ReceiveBugReport:
|
||||
Print("Скачать баг репорт по ключу " + request.arg);
|
||||
File bugArchive = Paths.get(CommonUtils.getHomePath(), "Bugs", request.arg).toFile();
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = CommonUtils.fileToBytes(bugArchive);
|
||||
break;
|
||||
case SendBugReport:
|
||||
Print("Отправить баг репорт " + request.arg);
|
||||
File bugArchive1 = Paths.get(CommonUtils.getHomePath(), "Bugs", request.arg).toFile();
|
||||
CommonUtils.bytesToFile((byte[]) request.object, bugArchive1);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
//</editor-fold>
|
||||
case GetComponentsBackups:
|
||||
Print("Получить список сохраненных версий компонента " + request.arg);
|
||||
File backupsDirectory = Paths.get(CommonUtils.getHomePath(), "Components", request.arg, "Backups").toFile();
|
||||
//--
|
||||
if (backupsDirectory.exists()) {
|
||||
File[] files = backupsDirectory.listFiles(File::isFile);
|
||||
if (files != null) {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
Vector<RemoteFile> res = new Vector<>();
|
||||
for (File file : files)
|
||||
res.add(new RemoteFile(file.getAbsolutePath(), false)); //тут всегда линух.
|
||||
response.object = res;
|
||||
} else
|
||||
throw new RepositoryRefuseException("Не удалось получить список предыдущих версий");
|
||||
} else {
|
||||
//баги еще не создавались. штатная ситуация.
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = new Vector<>();
|
||||
}
|
||||
break;
|
||||
case PublishComponent:
|
||||
String[] packed = request.arg.split("\n");
|
||||
String sComponentType = packed[0];
|
||||
String componentFileName = packed[1];
|
||||
String sComponentVersion = packed[2];
|
||||
String componentChangeRecord = request.arg.substring(
|
||||
sComponentType.length() +
|
||||
componentFileName.length() +
|
||||
sComponentVersion.length() +
|
||||
3
|
||||
);
|
||||
Print("Опубликовать компонент " + sComponentType);
|
||||
File componentFile = Paths.get(CommonUtils.getHomePath(), "Components", sComponentType, componentFileName).toFile();
|
||||
File versionFile = Paths.get(CommonUtils.getHomePath(), "Components", sComponentType, "version.txt").toFile();
|
||||
File backupsFolder = Paths.get(CommonUtils.getHomePath(), "Components", sComponentType, "Backups").toFile();
|
||||
//0 архивация старой версии, если она есть.
|
||||
if (componentFile.exists()) {
|
||||
String versionText = "";
|
||||
if (versionFile.exists())
|
||||
versionText = Utils.ReadAllText(versionFile);
|
||||
//---->>
|
||||
Utils.CheckDirectory(backupsFolder);
|
||||
Utils.keepNewFiles(backupsFolder, Global.properties.ComponentsBackUpsCount);
|
||||
//-->>
|
||||
File backupFile = new File(backupsFolder, sComponentType + "_" + versionText);
|
||||
if (backupFile.exists())
|
||||
Utils.delete_with_check(backupFile);
|
||||
FileUtils.moveFile(componentFile, backupFile);
|
||||
}
|
||||
//1 распаковка компонента
|
||||
CommonUtils.bytesToFile((byte[]) request.object, componentFile);
|
||||
//2 запись версии компонента
|
||||
FileUtils.writeStringToFile(versionFile, sComponentVersion);
|
||||
//3 запись в журнал компонента
|
||||
File changesLog = Paths.get(CommonUtils.getHomePath(), "Components", sComponentType, "changes.txt").toFile();
|
||||
FileWriter writer = new FileWriter(changesLog.getAbsolutePath(), true);
|
||||
BufferedWriter bufferWriter = new BufferedWriter(writer);
|
||||
bufferWriter.write(componentChangeRecord);
|
||||
bufferWriter.close();
|
||||
//-
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case UpdateComponentMinimalVersion:
|
||||
String[] packed_ = request.arg.split("\n");
|
||||
String sComponentType_ = packed_[0];
|
||||
String sComponentMinimalVersion = packed_[1];
|
||||
Print("Поднять минимальную версию компонента " + sComponentType_);
|
||||
File minimal_versionFile = Paths.get(CommonUtils.getHomePath(), "Components", sComponentType_, "minimal_version.txt").toFile();
|
||||
FileUtils.writeStringToFile(minimal_versionFile, sComponentMinimalVersion);
|
||||
//-
|
||||
//3 запись в журнал компонента
|
||||
File changesLog_ = Paths.get(CommonUtils.getHomePath(), "Components", sComponentType_, "changes.txt").toFile();
|
||||
FileWriter writer_ = new FileWriter(changesLog_.getAbsolutePath(), true);
|
||||
BufferedWriter bufferWriter_ = new BufferedWriter(writer_);
|
||||
bufferWriter_.write("Минимальная версия поднята до " + sComponentMinimalVersion + "\n");
|
||||
bufferWriter_.close();
|
||||
//-
|
||||
//-
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case ReceiveComponent:
|
||||
String[] packed1 = request.arg.split("\n");
|
||||
//тип/имя файла
|
||||
File componentFile1 = Paths.get(CommonUtils.getHomePath(), "Components", packed1[0], packed1[1]).toFile();
|
||||
Print("Получить компонент " + packed1[0]);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = CommonUtils.fileToBytes(componentFile1);
|
||||
break;
|
||||
default:
|
||||
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
||||
case GetComponentsVersions:
|
||||
Print("Получить актуальные версии компонентов (NEW)");
|
||||
String[] types = request.arg.split("\n");
|
||||
LinkedHashMap<ComponentType, String> response_actual_versions_ = new LinkedHashMap<>();
|
||||
for (String sType : types) {
|
||||
ComponentType componentType = ComponentType.valueOf(sType);
|
||||
File vFile = Paths.get(CommonUtils.getHomePath(), "Components", sType, "version.txt").toFile();
|
||||
String v_string = CommonUtils.removeCharacters(
|
||||
Utils.ReadAllText(vFile),
|
||||
"\n", "\r"
|
||||
);
|
||||
response_actual_versions_.put(componentType, v_string);
|
||||
}
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = response_actual_versions_;
|
||||
break;
|
||||
case GetComponentsMinimalVersions:
|
||||
Print("Получить минимальные версии компонентов (NEW)");
|
||||
String[] types_ = request.arg.split("\n");
|
||||
LinkedHashMap<ComponentType, String> response_minimal_versions_ = new LinkedHashMap<>();
|
||||
for (String sType : types_) {
|
||||
ComponentType componentType = ComponentType.valueOf(sType);
|
||||
File vFile = Paths.get(CommonUtils.getHomePath(), "Components", sType, "minimal_version.txt").toFile();
|
||||
String mv_string = CommonUtils.removeCharacters(
|
||||
Utils.ReadAllText(vFile),
|
||||
"\n", "\r"
|
||||
);
|
||||
response_minimal_versions_.put(componentType, mv_string);
|
||||
}
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = response_minimal_versions_;
|
||||
break;
|
||||
case GetComponentChangesLog:
|
||||
Print("Получить журнал изменений компонента " + request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = CommonUtils.fileToBytes(Paths.get(CommonUtils.getHomePath(), "Components", request.arg, "changes.txt").toFile());
|
||||
break;
|
||||
case CheckURLRegistered:
|
||||
Print("Проверить учетную запись на машине");
|
||||
String[] data = request.arg.split("\n");
|
||||
String email = data[0];
|
||||
String machineURL = data[1];
|
||||
String login = data[2];
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = db.workspaces.findWorkspace(email, machineURL, login);
|
||||
break;
|
||||
case DVMConvertProject:
|
||||
Print("Сконвертировать проект в DVM код");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
String[] args = request.arg.split("\n");
|
||||
//-
|
||||
String projectName = args[0];
|
||||
LanguageName projectLanguage = LanguageName.valueOf(args[1]);
|
||||
String options = args[2];
|
||||
Vector<String> filesNames = new Vector<>(Arrays.asList(args).subList(3, args.length));
|
||||
//-
|
||||
File workspace = Utils.getTempFileName("convertation");
|
||||
FileUtils.forceMkdir(workspace);
|
||||
File archive = new File(workspace, projectName + ".zip");
|
||||
request.Unpack(archive);
|
||||
File project = new File(workspace, projectName);
|
||||
Vector<String> badFiles = new Vector<>();
|
||||
if (unzip.Do(archive.getAbsolutePath(), workspace.getAbsolutePath()) && project.exists()) {
|
||||
String output = "";
|
||||
for (String fileName : filesNames) {
|
||||
File program = Paths.get(project.getAbsolutePath(), fileName).toFile();
|
||||
//--
|
||||
File convertedProgram = Paths.get(program.getParent(),
|
||||
CommonUtils.getFileNameWithoutExtension(program) + ".DVMH." +
|
||||
(projectLanguage.equals(LanguageName.fortran) ? "f" : "c")
|
||||
).toFile();
|
||||
String command =
|
||||
CommonUtils.DQuotes(server_dvm_drv) + " " +
|
||||
projectLanguage.getDVMCompile() + "dv " +
|
||||
options + " "
|
||||
+ CommonUtils.DQuotes(program.getName());
|
||||
//--
|
||||
File fileWorkspace = program.getParentFile();
|
||||
Process process = Utils.startScript(workspace, fileWorkspace, CommonUtils.getDateName("convert_script"), command);
|
||||
process.waitFor();
|
||||
String convertationOut = Utils.readAllOutput(process);
|
||||
convertationOut = convertationOut.replace(program.getName(), fileName); //для учета пути.
|
||||
if (!convertationOut.isEmpty())
|
||||
output += convertationOut + "\n";
|
||||
try {
|
||||
if (convertedProgram.exists()) {
|
||||
FileUtils.forceDelete(program);
|
||||
convertedProgram.renameTo(program);
|
||||
} else badFiles.add(program.getName());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
//--
|
||||
}
|
||||
response.arg = String.join("\n", badFiles) + "|" + output;
|
||||
File resultArchive = new File(workspace, projectName + "_result.zip");
|
||||
if (ComponentsServer.zip.Do(project.getAbsolutePath(), resultArchive.getAbsolutePath())) {
|
||||
response.object = CommonUtils.fileToBytes(resultArchive);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Внутренняя ошибка. Не удалось запаковать версию");
|
||||
//--
|
||||
} else
|
||||
throw new RepositoryRefuseException("Внутренняя ошибка. Не удалось распаковать проект");
|
||||
break;
|
||||
}
|
||||
} else
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OLD);
|
||||
}
|
||||
@Override
|
||||
protected void startAdditionalThreads() {
|
||||
backUp.start();
|
||||
}
|
||||
public static ZipFolderPass zip = new ZipFolderPass();
|
||||
public static UnzipFolderPass unzip = new UnzipFolderPass();
|
||||
public static ArchivesBackupPass backupSession = new ArchivesBackupPass();
|
||||
//-
|
||||
public static Vector<Pair<Machine, User>> storages =
|
||||
new Vector<>(Arrays.asList(
|
||||
new Pair<>(
|
||||
new Machine("titan", "dvmh.keldysh.ru", 22, MachineType.Server),
|
||||
new User("dvmuser1", "mprit_2011"))
|
||||
/*
|
||||
new Pair<>(
|
||||
new Machine("k100", "k100.kiam.ru", 22, MachineType.Server),
|
||||
new User("dvmuser1", "mprit_2011"))
|
||||
*/
|
||||
)
|
||||
);
|
||||
//-
|
||||
protected Thread backUp = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
//-------------------------------------
|
||||
Calendar rightNow = Calendar.getInstance();
|
||||
int year = rightNow.get(Calendar.YEAR);
|
||||
int month = rightNow.get(Calendar.MONTH);
|
||||
int day = rightNow.get(Calendar.DAY_OF_MONTH);
|
||||
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = rightNow.get(Calendar.MINUTE);
|
||||
if ((hour == Global.properties.BackupHour) && (minute == Global.properties.BackupMinute)) {
|
||||
//определить имя папки с багом.
|
||||
String backUpName = year + "_" + (month + 1) + "_" + (day);
|
||||
File todayBackUp = Paths.get(Global.DataBackUpsDirectory.getAbsolutePath(), backUpName).toFile();
|
||||
File todayBackUpArchive = Paths.get(Global.DataBackUpsDirectory.getAbsolutePath(), backUpName + ".zip").toFile();
|
||||
//-
|
||||
File bugsDBBackUp = Paths.get(todayBackUp.getAbsolutePath(), db.getFile().getName()).toFile();
|
||||
File bugsArchives = Paths.get(todayBackUp.getAbsolutePath(), "Bugs.zip").toFile();
|
||||
//-
|
||||
// Чистка старых бекапов на самом сервере.
|
||||
Utils.keepNewFiles(todayBackUp.getParentFile(), 2);
|
||||
if (!todayBackUpArchive.exists()) {
|
||||
FileUtils.forceMkdir(todayBackUp);
|
||||
Files.copy(db.getFile().toPath(), bugsDBBackUp.toPath());
|
||||
//-
|
||||
zip.Do("Bugs", bugsArchives.getAbsolutePath());
|
||||
zip.Do(todayBackUp.getAbsolutePath(), todayBackUpArchive.getAbsolutePath());
|
||||
Utils.forceDeleteWithCheck(todayBackUp);
|
||||
//-
|
||||
for (Pair<Machine, User> cred : storages) {
|
||||
backupSession.Do(cred.getKey(), cred.getValue(),
|
||||
todayBackUpArchive
|
||||
);
|
||||
}
|
||||
//bonus backup
|
||||
if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
|
||||
EmailMessage message = new EmailMessage(
|
||||
"db backup",
|
||||
"копия баз данных журнала ошибок",
|
||||
new Vector<>()
|
||||
);
|
||||
Email(message, db.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------
|
||||
Thread.sleep(60000);
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package _VisualDVM.Repository.Server;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
public class DiagnosticSignalHandler implements SignalHandler {
|
||||
private SignalHandler oldHandler;
|
||||
private SignalHandler handler;
|
||||
public DiagnosticSignalHandler() {
|
||||
}
|
||||
// Static method to install the signal handler
|
||||
public static void install(String signalName, SignalHandler handler) {
|
||||
Signal signal = new Signal(signalName);
|
||||
DiagnosticSignalHandler diagnosticSignalHandler = new DiagnosticSignalHandler();
|
||||
SignalHandler oldHandler = Signal.handle(signal, diagnosticSignalHandler);
|
||||
diagnosticSignalHandler.setHandler(handler);
|
||||
diagnosticSignalHandler.setOldHandler(oldHandler);
|
||||
}
|
||||
private void setOldHandler(SignalHandler oldHandler) {
|
||||
this.oldHandler = oldHandler;
|
||||
}
|
||||
private void setHandler(SignalHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
// Signal handler method
|
||||
// Signal handler method
|
||||
@Override
|
||||
public void handle(Signal sig) {
|
||||
System.out.println("Diagnostic Signal handler called for signal " + sig);
|
||||
try {
|
||||
FileUtils.writeStringToFile(new File("got SIG" + sig.getName() + " " + new Date().toString().replace(':', '_')), "");
|
||||
handler.handle(sig);
|
||||
// Chain back to previous handler, if one exists
|
||||
if (oldHandler != SIG_DFL && oldHandler != SIG_IGN) {
|
||||
oldHandler.handle(sig);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Signal handler failed, reason " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
92
src/_VisualDVM/Repository/Server/ServerCode.java
Normal file
92
src/_VisualDVM/Repository/Server/ServerCode.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package _VisualDVM.Repository.Server;
|
||||
public enum ServerCode {
|
||||
Undefined,
|
||||
ReadFile,
|
||||
SendFile,
|
||||
ReceiveFile,
|
||||
//--
|
||||
RegisterSubscriber,
|
||||
CheckSubscriberRole,
|
||||
//-
|
||||
GetComponentsBackups,
|
||||
//-
|
||||
UpdateBugReportField,
|
||||
UpdateBugReport,
|
||||
//-
|
||||
Email,
|
||||
ReceiveAllArchives,
|
||||
//-
|
||||
DownloadTest,
|
||||
//-
|
||||
OK,
|
||||
//-
|
||||
GetTestProject,
|
||||
StartTests,
|
||||
//-
|
||||
RefreshDVMTests, //- для админа. получение тестов из репозитория.
|
||||
//-
|
||||
EditObject,
|
||||
DeleteObject, //--------------------УСТАРЕЛО. УБРАТЬ.
|
||||
GetObjectCopyByPK,
|
||||
GetObjectsCopiesByPK,
|
||||
DeleteObjects,
|
||||
DeleteObjectsByPK,
|
||||
CheckObjectExistense, //
|
||||
//--
|
||||
EXIT,
|
||||
//--
|
||||
FAIL,
|
||||
//--
|
||||
ReceiveBugReportsDatabase,
|
||||
ReceiveTestsDatabase,
|
||||
ReceiveTestsTasksDatabase,
|
||||
PublishComponent,
|
||||
UpdateComponentMinimalVersion, //возможно потом, слить воедино с публикацией?
|
||||
ReceiveComponent,
|
||||
ReceiveBugReport,
|
||||
SendBugReport,
|
||||
GetComponentsVersions,
|
||||
GetComponentsMinimalVersions,
|
||||
GetComponentChangesLog,
|
||||
//--
|
||||
CheckURLRegistered,
|
||||
DVMConvertProject,
|
||||
SetRole,
|
||||
Patch,
|
||||
EmailSapforAssembly,
|
||||
//-
|
||||
DeleteObjectByPK,
|
||||
//-
|
||||
OLD,
|
||||
//-
|
||||
PublishAccount,
|
||||
GetActualSapforPackageData,
|
||||
//--
|
||||
PublishObject,
|
||||
PublishObjects,
|
||||
UpdateTestTasks,
|
||||
ActualizeSAPFORPackages,
|
||||
ActualizeDVMPackages,
|
||||
GetFirstActiveDVMPackage,
|
||||
DVMPackageNeedsKill, // не доделано.
|
||||
UpdateActiveDVMPackages,
|
||||
GetFirstActiveSapforPackages,
|
||||
SapforPackageNeedsKill,
|
||||
UpdateActiveSapforPackages,
|
||||
DownloadDVMPackage,
|
||||
DownloadDVMPackages,
|
||||
DownloadSapforPackage,
|
||||
ReplaceTestCode,
|
||||
ReplaceTestsCodes,
|
||||
GetDVMPackagesJson,
|
||||
GetSapforPackagesJson,
|
||||
GetFirstsActiveDVMPackages,
|
||||
Ping,
|
||||
GetFirstActiveDVMPackageForMachineURL,
|
||||
GetServerName,
|
||||
StartNecessaryMachines,
|
||||
GetSapforForCompilation,
|
||||
GetMaxSapforVersion,
|
||||
PerformAutoSapforTesting
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package _VisualDVM.Repository.Server;
|
||||
import Common.Utils.CommonUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
public class ServerExchangeUnit_2021 implements Serializable {
|
||||
public String codeName;
|
||||
public String arg;
|
||||
public Serializable object;
|
||||
//--------
|
||||
public ServerExchangeUnit_2021(ServerCode code_in, String arg_in, Serializable object_in) {
|
||||
codeName = code_in.toString();
|
||||
arg = arg_in;
|
||||
object = object_in;
|
||||
}
|
||||
public ServerExchangeUnit_2021(ServerCode code_in, String arg_in) {
|
||||
codeName = code_in.toString();
|
||||
arg = arg_in;
|
||||
object = null;
|
||||
}
|
||||
public ServerExchangeUnit_2021(ServerCode code_in) {
|
||||
codeName = code_in.toString();
|
||||
arg = null;
|
||||
object = null;
|
||||
}
|
||||
//--------
|
||||
public ServerCode getCode() throws Exception {
|
||||
return ServerCode.valueOf(codeName);
|
||||
}
|
||||
//--------
|
||||
public void Unpack() throws Exception {
|
||||
CommonUtils.bytesToFile((byte[]) object, new File(arg));
|
||||
}
|
||||
public void Unpack(File file) throws Exception {
|
||||
CommonUtils.bytesToFile((byte[]) object, file);
|
||||
}
|
||||
public void Print() {
|
||||
System.out.println("codeName=" + CommonUtils.Brackets(codeName));
|
||||
System.out.println(arg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package _VisualDVM.Repository.SubscriberRights;
|
||||
import Common.Database.Objects.DBObject;
|
||||
public class SubscriberRights extends DBObject {
|
||||
public String email; //почта
|
||||
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package _VisualDVM.Repository.SubscriberWorkspace;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Database.Objects.iDBObject;
|
||||
public class SubscriberWorkspace extends iDBObject {
|
||||
public String email; //почта
|
||||
public String URL; //адрес:порт машины
|
||||
public String login; // имя пользователя
|
||||
public String path; //рабочая папка на машине
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Current.HasSubscriber()&&
|
||||
Current.getSubscriber().address.equals(email)&&
|
||||
(Current.getAccount().isAdmin() || Current.getAccount().email.equals(Current.getSubscriber().address));
|
||||
}
|
||||
//-
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package _VisualDVM.Repository.SubscriberWorkspace;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Database.Tables.iDBTable;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
public class SubscriberWorkspaceDBTable extends iDBTable<SubscriberWorkspace> {
|
||||
public SubscriberWorkspaceDBTable() {
|
||||
super(SubscriberWorkspace.class);
|
||||
}
|
||||
public SubscriberWorkspace findWorkspace(String email, String machineURL, String login) {
|
||||
return this.Data.values().stream().filter(subscriberWorkspace ->
|
||||
subscriberWorkspace.email.equals(email) &&
|
||||
subscriberWorkspace.URL.equals(machineURL) &&
|
||||
subscriberWorkspace.login.equals(login)).findFirst().orElse(null);
|
||||
}
|
||||
//--
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "рабочая папка";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "рабочие папки";
|
||||
}
|
||||
@Override
|
||||
public Current CurrentName() {
|
||||
return Current.SubscriberWorkspace;
|
||||
}
|
||||
//-
|
||||
@Override
|
||||
public String[] getUIColumnNames() {
|
||||
return new String[]{"URL", "пользователь", "папка"};
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI() {
|
||||
return new DataSetControlForm(this);
|
||||
}
|
||||
@Override
|
||||
public Object getFieldAt(SubscriberWorkspace object, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 1:
|
||||
return object.URL;
|
||||
case 2:
|
||||
return object.login;
|
||||
case 3:
|
||||
return object.path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package _VisualDVM.Repository.SubscriberWorkspace;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
public class SubscriberWorkspacesMenuBar extends DataMenuBar {
|
||||
public SubscriberWorkspacesMenuBar() {
|
||||
super("рабочие пространства", PassCode_2021.DeleteSubscriberWorkspace);
|
||||
}
|
||||
}
|
||||
39
src/_VisualDVM/Repository/Subscribes/Subscriber.java
Normal file
39
src/_VisualDVM/Repository/Subscribes/Subscriber.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package _VisualDVM.Repository.Subscribes;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
public class Subscriber extends DBObject {
|
||||
@Description("PRIMARY KEY, UNIQUE")
|
||||
public String address = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String name = "";
|
||||
@Description("DEFAULT 'User'")
|
||||
public AccountRole role = AccountRole.User; //права доступа
|
||||
@Description("DEFAULT 1")
|
||||
public int mailOn = 1;
|
||||
//---
|
||||
public Subscriber() {
|
||||
}
|
||||
public Subscriber(String address_in) {
|
||||
address = address_in;
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return address;
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
Subscriber s = (Subscriber) src;
|
||||
name= s.name;
|
||||
role = s.role;
|
||||
mailOn= s.mailOn;
|
||||
}
|
||||
//как объект будут называть по внешним ключам.
|
||||
public String getFKName() {
|
||||
return "email";
|
||||
}
|
||||
public Object getEmptyFK() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
13
src/_VisualDVM/Repository/Subscribes/SubscribersMenuBar.java
Normal file
13
src/_VisualDVM/Repository/Subscribes/SubscribersMenuBar.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package _VisualDVM.Repository.Subscribes;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
public class SubscribersMenuBar extends DataMenuBar {
|
||||
public SubscribersMenuBar() {
|
||||
super("Адресаты",
|
||||
PassCode_2021.SaveBugReportExecutor,
|
||||
PassCode_2021.SaveBugReportRecipients,
|
||||
PassCode_2021.AddSubscriber,
|
||||
PassCode_2021.EditSubscriber,
|
||||
PassCode_2021.DeleteSubscriber);
|
||||
}
|
||||
}
|
||||
72
src/_VisualDVM/Repository/Subscribes/SubsribersDBTable.java
Normal file
72
src/_VisualDVM/Repository/Subscribes/SubsribersDBTable.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package _VisualDVM.Repository.Subscribes;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Database.Tables.FKBehaviour;
|
||||
import Common.Database.Tables.FKCurrentObjectBehaviuor;
|
||||
import Common.Database.Tables.FKDataBehaviour;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import _VisualDVM.Repository.SubscriberWorkspace.SubscriberWorkspace;
|
||||
import _VisualDVM.Repository.Subscribes.UI.SubscriberFields;
|
||||
import _VisualDVM.Repository.Subscribes.UI.SubscriberForm;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
public class SubsribersDBTable extends DBTable<String, Subscriber> {
|
||||
public SubsribersDBTable() {
|
||||
super(String.class, Subscriber.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "Адресат";
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI() {
|
||||
return new DataSetControlForm(this) {
|
||||
@Override
|
||||
public boolean hasCheckBox() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected void AdditionalInitColumns() {
|
||||
boolean admin = Current.getAccount().role.equals(AccountRole.Admin);
|
||||
columns.get(0).setVisible(admin);
|
||||
columns.get(1).setVisible(Current.getBugReport() != null);
|
||||
columns.get(3).setVisible(admin);
|
||||
columns.get(4).setVisible(admin);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public String[] getUIColumnNames() {
|
||||
return new String[]{"Имя", "Роль", "Рассылка"};
|
||||
}
|
||||
@Override
|
||||
public Object getFieldAt(Subscriber object, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 2:
|
||||
return object.name;
|
||||
case 3:
|
||||
return object.role.getDescription();
|
||||
case 4:
|
||||
return (object.mailOn==0)?"выключена":"включена";
|
||||
}
|
||||
return object.name;
|
||||
}
|
||||
@Override
|
||||
public Current CurrentName() {
|
||||
return Current.Subscriber;
|
||||
}
|
||||
@Override
|
||||
public DBObjectDialog<Subscriber, SubscriberFields> getDialog() {
|
||||
return new SubscriberForm();
|
||||
}
|
||||
@Override
|
||||
public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
|
||||
LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
|
||||
//-
|
||||
res.put(SubscriberWorkspace.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.Repository.Subscribes.UI.SubscriberFields">
|
||||
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="81c98" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="имя"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="8f1c6">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="4c488" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="адрес"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="675ad" class="javax.swing.JTextField" binding="tfName" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="a96c1" class="javax.swing.JTextField" binding="tfAddress" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="1c24b" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="роль"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="81d94" class="javax.swing.JComboBox" binding="cbRole" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="fe07e" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="рассылка"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e0879" class="javax.swing.JCheckBox" binding="cbMail">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<icon value="icons/NotPick.png"/>
|
||||
<selectedIcon value="icons/Pick.png"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Будет ли включена рассылка для этого пользователя"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,27 @@
|
||||
package _VisualDVM.Repository.Subscribes.UI;
|
||||
import Common.Visual.TextField.StyledTextField;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class SubscriberFields implements DialogFields {
|
||||
private JPanel content;
|
||||
public JTextField tfName;
|
||||
public JTextField tfAddress;
|
||||
public JComboBox<AccountRole> cbRole;
|
||||
public JCheckBox cbMail;
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
private void createUIComponents() {
|
||||
// TODO: place custom component creation code here
|
||||
tfName = new StyledTextField();
|
||||
tfAddress = new StyledTextField();
|
||||
cbRole = new JComboBox<>();
|
||||
cbRole.addItem(AccountRole.User);
|
||||
cbRole.addItem(AccountRole.Developer);
|
||||
cbRole.addItem(AccountRole.Admin);
|
||||
}
|
||||
}
|
||||
53
src/_VisualDVM/Repository/Subscribes/UI/SubscriberForm.java
Normal file
53
src/_VisualDVM/Repository/Subscribes/UI/SubscriberForm.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package _VisualDVM.Repository.Subscribes.UI;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import _VisualDVM.Repository.Subscribes.Subscriber;
|
||||
public class SubscriberForm extends DBObjectDialog<Subscriber, SubscriberFields> {
|
||||
public SubscriberForm() {
|
||||
super(SubscriberFields.class);
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 250;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 450;
|
||||
}
|
||||
@Override
|
||||
public void validateFields() {
|
||||
if (fields.tfName.getText().isEmpty())
|
||||
Log.Writeln("Имя учётной записи не может быть пустым");
|
||||
CommonUtils.validateEmail(fields.tfAddress.getText(), Log);
|
||||
if (fields.tfAddress.getText().isEmpty())
|
||||
Log.Writeln_("Адрес электронной почты не может быть пустым");
|
||||
if (!title_text.equals("Регистрация") && (fields.tfAddress.isEditable() && Global.componentsServer.db.subscribers.Data.containsKey(fields.tfAddress.getText()))) {
|
||||
Log.Writeln_("Адрес электронной почты " + CommonUtils.Brackets(fields.tfAddress.getText()) + " уже есть в списке.");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void fillFields() {
|
||||
fields.tfName.setText(Result.name);
|
||||
fields.tfAddress.setText(Result.address);
|
||||
fields.cbMail.setSelected(Result.mailOn!=0);
|
||||
CommonUI.TrySelect(fields.cbRole, Result.role);
|
||||
}
|
||||
@Override
|
||||
public void SetEditLimits() {
|
||||
fields.tfAddress.setEditable(false);
|
||||
}
|
||||
private AccountRole getSelectedRole() {
|
||||
return (AccountRole) fields.cbRole.getSelectedItem();
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result.name = fields.tfName.getText();
|
||||
Result.address = fields.tfAddress.getText();
|
||||
Result.mailOn = fields.cbMail.isSelected()?1:0;
|
||||
Result.role = getSelectedRole();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user