рефакторинг
This commit is contained in:
212
src/_VisualDVM/ComponentsServer/BugReport/BugReport.java
Normal file
212
src/_VisualDVM/ComponentsServer/BugReport/BugReport.java
Normal file
@@ -0,0 +1,212 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Objects.rDBObject;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Utils.Vector_;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.RecipientJson;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.RecipientsJson;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.VisualiserSettingsJson;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.Account;
|
||||
import _VisualDVM.ProjectData.SapforData.SapforProperties;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
public class BugReport extends rDBObject {
|
||||
public String project_version = "";
|
||||
public long visualiser_version = -1;
|
||||
public long sapfor_version = -1;
|
||||
public String comment = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String packedRecipientsJson = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String packedSettingsJson = ""; //устарело. (?)
|
||||
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;
|
||||
@Description("IGNORE")
|
||||
public byte[] packed_archive = null;
|
||||
public BugReport() {
|
||||
}
|
||||
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;
|
||||
packedSettingsJson = Utils_.gson.toJson(Global.mainModule.getProject().sapforProperties);
|
||||
percentage = 0;
|
||||
description = description_in;
|
||||
date = new Date().getTime();
|
||||
change_date = new Date().getTime();
|
||||
state = BugReportState.draft;
|
||||
owner = Global.mainModule.getProject().Home;
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
BugReport b = (BugReport) src;
|
||||
change_date = b.change_date;
|
||||
description = b.description;
|
||||
comment = b.comment;
|
||||
packedRecipientsJson = b.packedRecipientsJson;
|
||||
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;
|
||||
packedSettingsJson = b.packedSettingsJson;
|
||||
//-
|
||||
descriptionAdditionDraft = b.descriptionAdditionDraft;
|
||||
commentAdditionDraft = b.commentAdditionDraft;
|
||||
owner = b.owner;
|
||||
}
|
||||
//--
|
||||
public File getArchiveFile() {
|
||||
return Paths.get(System.getProperty("user.dir"), "Bugs", id + ".zip").toFile();
|
||||
}
|
||||
public String getDescriptionHeader() {
|
||||
if (description != null) {
|
||||
String[] data = description.split("\n");
|
||||
return (data.length > 0) ? data[0] : "";
|
||||
} else return "";
|
||||
}
|
||||
public boolean CheckNotDraft(TextLog log) {
|
||||
if (state.equals(BugReportState.draft)) {
|
||||
log.Writeln_("Отчёт об ошибке является черновиком");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public String getMailTitlePrefix() {
|
||||
return "Ошибка " + Utils_.Brackets(id) + ", автор " + Utils_.Brackets(sender_name) + " : ";
|
||||
}
|
||||
public File[] getAttachements() {
|
||||
File[] project_attachements = Global.mainModule.getProject().getAttachmentsDirectory().listFiles();
|
||||
File[] res = new File[project_attachements.length + 1];
|
||||
res[0] = getArchiveFile();
|
||||
for (int i = 0; i < project_attachements.length; ++i)
|
||||
res[i + 1] = project_attachements[i];
|
||||
return res;
|
||||
}
|
||||
public boolean CheckDraft(TextLog log) {
|
||||
if (!state.equals(BugReportState.draft)) {
|
||||
log.Writeln("Отчёт об ошибке не является черновиком. Он уже опубликован");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public String getNewMailText() {
|
||||
String res = String.join("\n",
|
||||
"Описание:", description, getPassport()
|
||||
);
|
||||
return res;
|
||||
}
|
||||
public String getSettingsSummary() {
|
||||
Vector<String> res = new Vector_<String>(
|
||||
(Global.mainModule.HasAccount() ? (Global.mainModule.getAccount().isAdmin() ? ("Адрес отправителя: " + sender_address + "\n") : "") : ""),
|
||||
"Версия SAPFOR: " + sapfor_version,
|
||||
"Версия визуализатора: " + visualiser_version,
|
||||
"----------------------------------"
|
||||
);
|
||||
if (!project_version.isEmpty()) {
|
||||
if (visualiser_version < 1134) {
|
||||
res.add(getSettingsJson().getSummary());
|
||||
} else {
|
||||
res.add(getPropertiesJson().getSummary());
|
||||
}
|
||||
}
|
||||
return String.join("\n", res);
|
||||
}
|
||||
public String getPassport() {
|
||||
return String.join("\n",
|
||||
Constants.separator,
|
||||
"Отправитель: " + sender_name,
|
||||
"Исполнитель: " + executor,
|
||||
"Проект: " + project_version,
|
||||
Constants.separator,
|
||||
getSettingsSummary(),
|
||||
Constants.separator);
|
||||
}
|
||||
public boolean isNoneProject() {
|
||||
return project_version.isEmpty();
|
||||
}
|
||||
//--->
|
||||
public void CheckSubscribers() {
|
||||
for (Subscriber subscriber : Global.componentsServer.db.subscribers.Data.values())
|
||||
subscriber.Select(packedRecipientsJson.contains(subscriber.address));
|
||||
}
|
||||
public void saveRecipientsAsJson(Vector<Subscriber> subscribers) {
|
||||
packedRecipientsJson = Utils_.gson.toJson(new RecipientsJson(subscribers));
|
||||
}
|
||||
public Vector<String> getRecipients() {
|
||||
Vector<String> res = new Vector<>();
|
||||
if (packedRecipientsJson.isEmpty()) return res;
|
||||
RecipientsJson recipients = Utils_.gson.fromJson(packedRecipientsJson, RecipientsJson.class);
|
||||
for (RecipientJson recipientJson : recipients.array) {
|
||||
res.add(recipientJson.address);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public VisualiserSettingsJson getSettingsJson() {
|
||||
return packedSettingsJson.isEmpty() ? new VisualiserSettingsJson() : Utils_.gson.fromJson(packedSettingsJson, VisualiserSettingsJson.class);
|
||||
}
|
||||
public SapforProperties getPropertiesJson() {
|
||||
return packedSettingsJson.isEmpty() ? new SapforProperties() : Utils_.gson.fromJson(packedSettingsJson, SapforProperties.class);
|
||||
}
|
||||
public boolean canAppend(Account account, TextLog log) {
|
||||
if (account.CheckRegistered(log)) {
|
||||
if (account.email.equals(sender_address) || account.email.equals(executor_address)) {
|
||||
return true;
|
||||
} else {
|
||||
switch (account.role) {
|
||||
case Admin:
|
||||
case Developer:
|
||||
return true;
|
||||
default:
|
||||
if (log != null)
|
||||
log.Writeln_("Вы не являетесь автором, исполнителем, разработчиком, или администратором");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean canModify(Account account, TextLog log) {
|
||||
if (account.CheckRegistered(log)) {
|
||||
switch (account.role) {
|
||||
case Admin:
|
||||
case Developer:
|
||||
return true;
|
||||
default:
|
||||
if (account.email.equals(sender_address)) return true;
|
||||
if (log != null) log.Writeln_("Вы не являетесь автором, разработчиком, или администратором");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Common.Visual.StatusEnum;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import _VisualDVM.ComponentsServer.BugReport.UI.BugReportsForm;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
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(JPanel mountPanel) {
|
||||
return new BugReportsForm(this, mountPanel);
|
||||
}
|
||||
public Vector<BugReport> getAllDrafts() throws Exception {
|
||||
return Data.values().stream().filter(bugReport -> bugReport.state.equals(BugReportState.draft)).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
//-
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
public class BugReportAdditionJson implements Serializable {
|
||||
@Expose
|
||||
public String id = "";
|
||||
@Expose
|
||||
public String fieldName = "";
|
||||
@Expose
|
||||
public String textAddition ="";
|
||||
public BugReportAdditionJson(BugReport bugReport, String fieldName_in, String addition_in){
|
||||
id = bugReport.id;
|
||||
fieldName = fieldName_in;
|
||||
textAddition = addition_in;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import com.google.gson.annotations.Expose;
|
||||
public class RecipientJson {
|
||||
@Expose
|
||||
public String address;
|
||||
public RecipientJson(String addres_in) {
|
||||
address= addres_in;
|
||||
}
|
||||
public RecipientJson() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class RecipientsJson {
|
||||
@Expose
|
||||
public List<RecipientJson> array = new Vector<>();
|
||||
public RecipientsJson() {
|
||||
}
|
||||
//при создании пакета.
|
||||
public RecipientsJson(Vector<? extends Subscriber> subscribers) {
|
||||
array = new Vector<>();
|
||||
for (Subscriber subscriber : subscribers)
|
||||
array.add(new RecipientJson(subscriber.address));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import com.google.gson.annotations.Expose;
|
||||
public class VisualiserSettingJson {
|
||||
@Expose
|
||||
public String name;
|
||||
@Expose
|
||||
public String value;
|
||||
public VisualiserSettingJson(){
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.Json;
|
||||
import _VisualDVM.ProjectData.SapforData.SapforProperties;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class VisualiserSettingsJson {
|
||||
@Expose
|
||||
public List<VisualiserSettingJson> array = new Vector<>();
|
||||
public String getSummary() {
|
||||
SapforProperties properties = new SapforProperties(); //только для извлечения описаний.
|
||||
Vector<String> res = new Vector<>();
|
||||
for (VisualiserSettingJson setting : array) {
|
||||
try {
|
||||
res.add(properties.getFieldDescription(setting.name) + "=" + setting.value);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return String.join("\n", res);
|
||||
}
|
||||
}
|
||||
177
src/_VisualDVM/ComponentsServer/BugReport/UI/BugReportsForm.java
Normal file
177
src/_VisualDVM/ComponentsServer/BugReport/UI/BugReportsForm.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package _VisualDVM.ComponentsServer.BugReport.UI;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import Common.Visual.Tables.RendererDate;
|
||||
import Common.Visual.Tables.RendererProgressBar;
|
||||
import Common.Visual.Tables.RendererStatusEnum;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReportState;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Comparator;
|
||||
public class BugReportsForm extends DataSetControlForm<BugReport> {
|
||||
//todo упразднить и раскидать по стандартным фильтрам. галки и столбцы
|
||||
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 BugReportsForm(DataSet<?, BugReport> dataSource_in, JPanel mountPanel_in) {
|
||||
super(dataSource_in, mountPanel_in);
|
||||
}
|
||||
@Override
|
||||
protected void createColumns() {
|
||||
AddColumns(
|
||||
new ColumnInfo<BugReport>("Описание") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.getDescriptionHeader();
|
||||
}
|
||||
@Override
|
||||
public int getMaxWidth() {
|
||||
return 600;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Отправитель") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.sender_name;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Исполнитель") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.executor;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Проект") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.project_version;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Завершенность") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.percentage;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererProgressBar.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Дата создания") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.date;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererDate.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Дата изменения") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.change_date;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererDate.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<BugReport>("Статус") {
|
||||
@Override
|
||||
public Object getFieldAt(BugReport object) {
|
||||
return object.state;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererStatusEnum.class;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@Override
|
||||
protected boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void ShowCurrentObject() throws Exception {
|
||||
super.ShowCurrentObject();
|
||||
Global.mainModule.getUI().getMainWindow().getCallbackWindow().ShowCurrentBugReport();
|
||||
}
|
||||
@Override
|
||||
protected void ShowNoCurrentObject() throws Exception {
|
||||
super.ShowNoCurrentObject();
|
||||
Global.mainModule.getUI().getMainWindow().getCallbackWindow().ShowNoCurrentBugReport();
|
||||
}
|
||||
@Override
|
||||
protected void MouseAction2() throws Exception {
|
||||
Global.mainModule.getPass(PassCode.OpenBugReportTestProject).Do();
|
||||
}
|
||||
@Override
|
||||
protected 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) {
|
||||
Global.mainModule.getPass(PassCode.OpenBugReportTestProject).Do();
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public PassCode_ getDeletePassCode() {
|
||||
return PassCode.DeleteBugReport;
|
||||
}
|
||||
@Override
|
||||
public DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription(),
|
||||
PassCode.SynchronizeBugReports,
|
||||
PassCode.DownloadAllBugReportsArchives,
|
||||
PassCode.AddBugReport,
|
||||
PassCode.PublishBugReport,
|
||||
PassCode.OpenBugReportTestProject,
|
||||
PassCode.OpenBugReport,
|
||||
PassCode.UpdateBugReportProgress,
|
||||
PassCode.CloseBugReport,
|
||||
PassCode.DeleteBugReport);
|
||||
}
|
||||
@Override
|
||||
protected Comparator<BugReport> getDefaultComparator() {
|
||||
return (o1, o2) -> -(o1.getDate().compareTo(o2.getDate()));
|
||||
}
|
||||
@Override
|
||||
public boolean isObjectVisible(BugReport object) {
|
||||
return super.isObjectVisible(object) && (
|
||||
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(Global.mainModule.getAccount().email) ||
|
||||
object.executor_address.equalsIgnoreCase(Global.mainModule.getAccount().email)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
47
src/_VisualDVM/ComponentsServer/BugReportsDatabase.java
Normal file
47
src/_VisualDVM/ComponentsServer/BugReportsDatabase.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package _VisualDVM.ComponentsServer;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReportsDBTable;
|
||||
import _VisualDVM.ComponentsServer.SubscriberWorkspace.SubscriberWorkspaceDBTable;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.SubsribersDBTable;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
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", "bug_reports.sqlite").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 getSynchronizePassCode() {
|
||||
return PassCode.SynchronizeBugReports;
|
||||
}
|
||||
public void DeleteDrafts() throws Exception {
|
||||
Vector<BugReport> drafts = bugReports.getAllDrafts();
|
||||
for (BugReport draft : drafts)
|
||||
Delete(draft);
|
||||
}
|
||||
public void DropUI() {
|
||||
SaveLastSelections();
|
||||
bugReports.ClearUI();
|
||||
subscribers.ClearUI();
|
||||
workspaces.ClearUI();
|
||||
}
|
||||
public void ResetUI() {
|
||||
bugReports.ShowUI();
|
||||
RestoreLastSelections();
|
||||
}
|
||||
}
|
||||
134
src/_VisualDVM/ComponentsServer/Component/Component.java
Normal file
134
src/_VisualDVM/ComponentsServer/Component/Component.java
Normal file
@@ -0,0 +1,134 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.CommonConstants;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Utils.Loggable;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.Windows.Dialog.VFileChooser;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
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 = "";
|
||||
VFileChooser fileChooser = null; ///для ручной установки.
|
||||
private ComponentState state;
|
||||
public abstract ComponentType getComponentType();
|
||||
public VFileChooser getFileChooser() {
|
||||
return (fileChooser == null) ? (fileChooser = new VFileChooser("выбор файла для компонента " +
|
||||
Utils_.Brackets(getComponentType().getDescription()), Utils_.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_.forceDeleteWithCheck(getFile());
|
||||
//-скопировать файл
|
||||
Files.move(getNewFile().toPath(), getFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
//удалить новый файл.
|
||||
Utils_.forceDeleteWithCheck(getNewFile());
|
||||
}
|
||||
public void Update() throws Exception {
|
||||
if (!getNewFile().setExecutable(true)) throw new PassException("Не удалось разрешить файл\n" +
|
||||
getNewFile() +
|
||||
"\nна выполнение");
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return getComponentType();
|
||||
}
|
||||
public boolean isValidVersion(TextLog Log, String desc) {
|
||||
if (version == CommonConstants.Nan) {
|
||||
Log.Writeln_("Не определена версия " + desc + " компонента " + Utils_.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Common.Visual.StatusEnum;
|
||||
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/ComponentsServer/Component/ComponentType.java
Normal file
35
src/_VisualDVM/ComponentsServer/Component/ComponentType.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package _VisualDVM.ComponentsServer.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 "?";
|
||||
}
|
||||
}
|
||||
}
|
||||
81
src/_VisualDVM/ComponentsServer/Component/ComponentsSet.java
Normal file
81
src/_VisualDVM/ComponentsServer/Component/ComponentsSet.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.MainModule_;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import _VisualDVM.ComponentsServer.Component.PerformanceAnalyzer.PerformanceAnalyzer;
|
||||
import _VisualDVM.ComponentsServer.Component.Sapfor.Sapfor_F;
|
||||
import _VisualDVM.ComponentsServer.Component.UI.ComponentsForm;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
import javax.swing.*;
|
||||
public class ComponentsSet extends DataSet<ComponentType, Component> {
|
||||
public boolean bad_state = false;
|
||||
public boolean need_update = false;
|
||||
public boolean need_publish = false;
|
||||
public ComponentsSet() {
|
||||
super(ComponentType.class, Component.class);
|
||||
put(ComponentType.Visualiser, Global.visualiser = new Visualiser());
|
||||
put(ComponentType.Sapfor_F, (Component) MainModule_.instance.set(Current.Sapfor, new Sapfor_F()));
|
||||
put(ComponentType.Visualizer_2, Global.visualizer_2);
|
||||
put(ComponentType.PerformanceAnalyzer, Global.performanceAnalyzer = new PerformanceAnalyzer());
|
||||
put(ComponentType.Instruction, new Instruction());
|
||||
}
|
||||
public boolean needChanges() {
|
||||
return bad_state || need_update;
|
||||
}
|
||||
public String getButtonIconPath() {
|
||||
return needChanges() ? "/icons/ComponentsNeedUpdate.gif"
|
||||
: (need_publish ? "/icons/ComponentsNeedPublish_2023.gif" : "/icons/ComponentsActual.png");
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "компонент";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "компоненты";
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||||
return new ComponentsForm(this, mountPanel);
|
||||
}
|
||||
//--
|
||||
public void refreshUpdatesStatus() {
|
||||
if (getUI() != null)
|
||||
getUI().RedrawControl();
|
||||
validateStates();
|
||||
if (Global.mainModule.getUI().hasMainWindow())
|
||||
Global.mainModule.getUI().getMainWindow().ShowUpdatesIcon();
|
||||
}
|
||||
public boolean validateStates() {
|
||||
bad_state = need_update = need_publish = false;
|
||||
for (Component component : Data.values()) {
|
||||
switch (component.getState()) {
|
||||
case Not_found:
|
||||
case Unknown_version:
|
||||
case Old_version:
|
||||
if (component.isNecessary())
|
||||
bad_state = true;
|
||||
component.Select(true);
|
||||
break;
|
||||
case Needs_update:
|
||||
need_update = true;
|
||||
component.Select(true);
|
||||
break;
|
||||
case Needs_publish:
|
||||
need_publish = true;
|
||||
break;
|
||||
default:
|
||||
component.Select(false);
|
||||
break;
|
||||
}
|
||||
// }
|
||||
}
|
||||
return !bad_state;
|
||||
}
|
||||
public void initialVersionsCheck() {
|
||||
for (Component component : Data.values())
|
||||
component.InitialVersionCheck();
|
||||
}
|
||||
}
|
||||
57
src/_VisualDVM/ComponentsServer/Component/Instruction.java
Normal file
57
src/_VisualDVM/ComponentsServer/Component/Instruction.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.Utils.Utils_;
|
||||
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) {
|
||||
Utils_.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package _VisualDVM.ComponentsServer.Component.Json;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.ComponentsServer.Component.Component;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
public class ComponentPublicationInfoJson implements Serializable {
|
||||
@Expose
|
||||
public ComponentType componentType = ComponentType.Undefined;
|
||||
@Expose
|
||||
public String fileName = "";
|
||||
@Expose
|
||||
public byte[] packedFile = null;
|
||||
@Expose
|
||||
public String versionText = "";
|
||||
@Expose
|
||||
public String changeRecord = "";
|
||||
@Expose
|
||||
public boolean needsUpdateMinimalVersion = false;
|
||||
public ComponentPublicationInfoJson(Component component) throws Exception{
|
||||
componentType = component.getComponentType();
|
||||
fileName = component.getFileName();
|
||||
packedFile = Utils_.fileToBytes(component.getFile());
|
||||
versionText = component.getVersionText();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package _VisualDVM.ComponentsServer.Component.Json;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
public class ComponentVersionsInfoJson implements Serializable {
|
||||
@Expose
|
||||
public ComponentType componentType = ComponentType.Undefined;
|
||||
@Expose
|
||||
public String minimal_version = "";
|
||||
@Expose
|
||||
public String actual_version = "";
|
||||
public ComponentVersionsInfoJson(ComponentType componentType_in){
|
||||
componentType=componentType_in;
|
||||
}
|
||||
}
|
||||
12
src/_VisualDVM/ComponentsServer/Component/OSDComponent.java
Normal file
12
src/_VisualDVM/ComponentsServer/Component/OSDComponent.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.Utils.Utils_;
|
||||
public abstract class OSDComponent extends Component {
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return getComponentType().toString() + (Utils_.isWindows() ? ".exe" : "");
|
||||
}
|
||||
@Override
|
||||
public String getNewFileName() {
|
||||
return getComponentType().toString() + "_new" + (Utils_.isWindows() ? ".exe" : "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package _VisualDVM.ComponentsServer.Component.PerformanceAnalyzer;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.ComponentsServer.Component.Component;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Utils;
|
||||
import analyzer.common.MessageJtoJ;
|
||||
|
||||
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 = Global.mainModule.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 " + Utils_.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(
|
||||
Global.mainModule.HasProject() ? Global.mainModule.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 " + Utils_.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) {
|
||||
UI.Info("Анализатор уже запущен");
|
||||
} else {
|
||||
main_thread = new Thread(this::ServerBody);
|
||||
main_thread.start();
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package _VisualDVM.ComponentsServer.Component.Sapfor;
|
||||
import Common.MainModule_;
|
||||
import Common.Utils.Utils_;
|
||||
|
||||
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 (MainModule_.instance.getUI().HasPassForm())
|
||||
MainModule_.instance.getUI().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) {
|
||||
Utils_.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
592
src/_VisualDVM/ComponentsServer/Component/Sapfor/Sapfor.java
Normal file
592
src/_VisualDVM/ComponentsServer/Component/Sapfor/Sapfor.java
Normal file
@@ -0,0 +1,592 @@
|
||||
package _VisualDVM.ComponentsServer.Component.Sapfor;
|
||||
import Common.CommonConstants;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.ComponentsServer.Component.OSDComponent;
|
||||
import _VisualDVM.ComponentsServer.Component.Visualizer_2;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.ProjectData.Files.UI.Editor.SPFEditor;
|
||||
import _VisualDVM.TestingSystem.Common.Test.Test;
|
||||
import _VisualDVM.Utils;
|
||||
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 static File temp_copy = null;
|
||||
//---
|
||||
public static TransformationPermission transformationPermission = TransformationPermission.None;
|
||||
public Vector<String> Intrinsics = new Vector<>();
|
||||
public LinkedHashMap<String, String> ModifiedFiles = new LinkedHashMap<>();
|
||||
public LinkedHashMap<String, String> OldFiles = new LinkedHashMap<>();
|
||||
int size;
|
||||
int[] sizes;
|
||||
String PID = "";
|
||||
private int errorCode;
|
||||
private String result;
|
||||
private String output;
|
||||
private String outputMessage;
|
||||
private String predictorStats;
|
||||
//-
|
||||
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 static PassCode[] getAnalysesCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_ParseFilesWithOrder,
|
||||
PassCode.SPF_GetFileLineInfo,
|
||||
PassCode.SPF_GetArrayDistributionOnlyRegions,
|
||||
PassCode.SPF_GetIncludeDependencies,
|
||||
PassCode.SPF_GetGraphLoops,
|
||||
PassCode.SPF_GetGraphFunctions,
|
||||
PassCode.SPF_GetAllDeclaratedArrays,
|
||||
PassCode.SPF_GetArrayDistributionOnlyAnalysis,
|
||||
PassCode.SPF_GetArrayDistribution
|
||||
};
|
||||
}
|
||||
public static PassCode[] getLoopsTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_LoopEndDoConverterPass,
|
||||
PassCode.SPF_LoopFission,
|
||||
PassCode.SPF_LoopUnion,
|
||||
PassCode.SPF_LoopUnrolling
|
||||
};
|
||||
}
|
||||
public static PassCode[] getPrivatesTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_PrivateShrinking,
|
||||
PassCode.SPF_PrivateExpansion,
|
||||
PassCode.SPF_PrivateRemoving,
|
||||
PassCode.SPF_InsertPrivateFromGUI
|
||||
};
|
||||
}
|
||||
public static PassCode[] getProceduresTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_InlineProcedures,
|
||||
PassCode.SPF_InlineProceduresH,
|
||||
PassCode.SPF_DuplicateFunctionChains,
|
||||
PassCode.SPF_RemoveUnusedFunctions
|
||||
};
|
||||
}
|
||||
public static PassCode[] getDVMTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_RemoveDvmDirectivesToComments,
|
||||
PassCode.SPF_RemoveDvmDirectives,
|
||||
PassCode.SPF_RemoveOmpDirectives
|
||||
};
|
||||
}
|
||||
public static PassCode[] getIntervalsTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_CreateIntervalsTree,
|
||||
PassCode.SPF_RemoveDvmIntervals
|
||||
};
|
||||
}
|
||||
public static PassCode[] getRegionsTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_ResolveParallelRegionConflicts,
|
||||
PassCode.SPF_InsertDvmhRegions,
|
||||
PassCode.SPF_RemoveDistArraysFromIO
|
||||
};
|
||||
}
|
||||
public static PassCode[] getPreparationTransformationsCodes() {
|
||||
return new PassCode[]{
|
||||
PassCode.SPF_RenameIncludes,
|
||||
PassCode.SPF_InsertIncludesPass,
|
||||
PassCode.SPF_CorrectCodeStylePass,
|
||||
PassCode.SPF_ConvertStructures,
|
||||
PassCode.SPF_CreateCheckpoints,
|
||||
PassCode.SPF_InitDeclsWithZero,
|
||||
PassCode.SPF_ExpressionSubstitution,
|
||||
PassCode.EraseBadSymbols,
|
||||
PassCode.SPF_RemoveComments,
|
||||
PassCode.SPF_RemoveDeadCode,
|
||||
PassCode.CombineFiles,
|
||||
PassCode.CopyProject,
|
||||
PassCode.PrepareForModulesAssembly,
|
||||
PassCode.DVMConvertProject,
|
||||
PassCode.SPF_ResolveCommonBlockConflicts,
|
||||
PassCode.SPF_InsertImplicitNone
|
||||
};
|
||||
}
|
||||
//----------
|
||||
public static Vector<PassCode> getScenariosCodes() {
|
||||
Vector<PassCode> res = new Vector<>();
|
||||
res.add(PassCode.SPF_InitDeclsWithZero);//+
|
||||
res.add(PassCode.SPF_ConvertStructures);//+
|
||||
res.add(PassCode.SPF_ExpressionSubstitution);//+
|
||||
//--
|
||||
res.add(PassCode.SPF_CreateCheckpoints); //+
|
||||
res.add(PassCode.SPF_CreateIntervalsTree);//+
|
||||
res.add(PassCode.SPF_RemoveDvmIntervals);//+
|
||||
//--
|
||||
res.add(PassCode.SPF_RemoveDvmDirectives); //+
|
||||
res.add(PassCode.SPF_RemoveDvmDirectivesToComments); //+
|
||||
res.add(PassCode.SPF_RemoveOmpDirectives);//+
|
||||
res.add(PassCode.SPF_RemoveComments);//+
|
||||
res.add(PassCode.SPF_RemoveDeadCode);//+
|
||||
res.add(PassCode.SPF_RenameIncludes);
|
||||
res.add(PassCode.SPF_InsertIncludesPass);//+
|
||||
//--
|
||||
res.add(PassCode.SPF_LoopEndDoConverterPass); //+
|
||||
res.add(PassCode.SPF_LoopUnion);//+
|
||||
res.add(PassCode.SPF_LoopFission);//+
|
||||
//--
|
||||
res.add(PassCode.SPF_PrivateShrinking);//+
|
||||
res.add(PassCode.SPF_PrivateExpansion);//+
|
||||
res.add(PassCode.SPF_PrivateRemoving);//+
|
||||
//--
|
||||
res.add(PassCode.SPF_RemoveUnusedFunctions);//+
|
||||
res.add(PassCode.SPF_DuplicateFunctionChains);//+
|
||||
//--
|
||||
res.add(PassCode.SPF_ResolveParallelRegionConflicts);//+
|
||||
res.add(PassCode.SPF_RemoveDistArraysFromIO);
|
||||
res.add(PassCode.SPF_ResolveCommonBlockConflicts);//+
|
||||
//-
|
||||
res.add(PassCode.SPF_InsertDvmhRegions);//+
|
||||
res.add(PassCode.SPF_SharedMemoryParallelization);//+
|
||||
res.add(PassCode.SPF_InsertImplicitNone);//+
|
||||
res.add(PassCode.CreateParallelVariants); //?
|
||||
return 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_.forceDeleteWithCheck(outputFile);
|
||||
Utils_.forceDeleteWithCheck(errorsFile);
|
||||
//---
|
||||
File file = new File(data_workspace, name + (Utils_.isWindows() ? ".bat" : ".sh"));
|
||||
FileUtils.write(file,
|
||||
Utils_.DQuotes(sapfor_drv)
|
||||
+ (flags.isEmpty() ? "" : (" " + flags))
|
||||
+ " -noLogo"
|
||||
+ " " + command +
|
||||
" 1>" +
|
||||
Utils_.DQuotes(outputFile.getAbsolutePath()) +
|
||||
" 2>" +
|
||||
Utils_.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) {
|
||||
Utils_.MainLog.PrintException(ex);
|
||||
Utils_.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 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 getTempCopy(File src) throws Exception {
|
||||
if (temp_copy == null || !temp_copy.exists()) {
|
||||
temp_copy = Utils.getTempFileName("SAPFOR" + (Utils_.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.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;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
//<editor-fold desc="компонент">
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
RunAnalysis("SPF_GetVersionAndBuildDate", -1, "", "");
|
||||
Visualizer_2.UnpackVersionInfo(this, getResult());
|
||||
} catch (Exception e) {
|
||||
Utils_.MainLog.PrintException(e);
|
||||
UI.Error("Не удалось получить версию компонента " + Utils_.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,
|
||||
"",
|
||||
Utils_.DQuotes(src.getAbsolutePath()) +
|
||||
" "
|
||||
+ Utils_.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: Не удалось перейти в папку "
|
||||
+ Utils_.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(Utils_.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();
|
||||
Global.mainModule.getProject().dropLastModification();
|
||||
DBProjectFile cuf = null;
|
||||
if (Global.mainModule.HasFile()) {
|
||||
cuf = Global.mainModule.getFile();
|
||||
Global.mainModule.getPass(PassCode.CloseCurrentFile).Do();
|
||||
}
|
||||
if (mode) //модификация
|
||||
{
|
||||
OldFiles.clear();
|
||||
for (String name : ModifiedFiles.keySet()) {
|
||||
if (Global.mainModule.getProject().db.files.Data.containsKey(name)) {
|
||||
File file = Global.mainModule.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 = Global.mainModule.getProject().db.files.Data.get(name).file;
|
||||
Utils.WriteToFile(file, OldFiles.get(name));
|
||||
}
|
||||
OldFiles.clear();
|
||||
} else UI.Info("Сохранение файлов отсутствует.");
|
||||
}
|
||||
if (cuf != null)
|
||||
Global.mainModule.getPass(PassCode.OpenCurrentFile).Do(cuf);
|
||||
}
|
||||
//</editor-fold>
|
||||
public SapforAnalysis getAnalysisByPhase(String phase) {
|
||||
for (PassCode analysis_code : getAnalysesCodes()) {
|
||||
SapforAnalysis analysis = (SapforAnalysis) Global.mainModule.getPass(analysis_code);
|
||||
if (analysis.phase().equals(phase)) return analysis;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void ResetAllAnalyses() {
|
||||
for (PassCode code : getAnalysesCodes())
|
||||
(Global.mainModule.getPass(code)).Reset();
|
||||
//------------------------------------------------------------------------------------------>>>> пакетный режим.
|
||||
if (UI.isActive()) {
|
||||
Global.mainModule.getPass(PassCode.Precompilation).Reset();
|
||||
Global.mainModule.getPass(PassCode.SPF_GetGCovInfo).Reset();
|
||||
}
|
||||
SPFEditor.enable_text_changed = false;
|
||||
transformationPermission = TransformationPermission.None;
|
||||
if ((UI.isActive()) && (Global.mainModule.getUI().hasMainWindow()) && (Global.mainModule.getUI().getVersionsWindow() != null))
|
||||
Global.mainModule.getUI().getVersionsWindow().BlockVariants();
|
||||
}
|
||||
//--------------------------------------------------------------------------->>
|
||||
//временный (?) проход, по тихому получить размерность теста, предварительно выполнив тихий парс.
|
||||
//тут все одноразовое. считаем что таблицы бд уже заполнены как надо.
|
||||
/*
|
||||
public LanguageStyle getStyle() throws Exception {
|
||||
return (Global.mainModule.getDb()).settings.get(SettingName.FREE_FORM).toBoolean() ? LanguageStyle.free : LanguageStyle.fixed;
|
||||
}
|
||||
*/
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
public String getConsoleFlags() throws Exception {
|
||||
Vector<String> res = new Vector<>();
|
||||
if ((Global.mainModule.getDb()).settings.get(SettingName.FREE_FORM).toBoolean())
|
||||
res.add("-f90");
|
||||
if ((Global.mainModule.getDb()).settings.get(SettingName.STATIC_SHADOW_ANALYSIS).toBoolean())
|
||||
res.add("-sh");
|
||||
res.add("-shwidth " + (Global.mainModule.getDb()).settings.get(SettingName.MAX_SHADOW_WIDTH));
|
||||
if ((Global.mainModule.getDb()).settings.get(SettingName.KEEP_SPF_DIRECTIVES).toBoolean())
|
||||
res.add("-keepSPF");
|
||||
return String.join(" ", res);
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package _VisualDVM.ComponentsServer.Component.Sapfor;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
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.ComponentsServer.Component.Sapfor;
|
||||
public enum TransformationPermission {
|
||||
None,
|
||||
All,
|
||||
VariantsOnly
|
||||
}
|
||||
@@ -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.ComponentsServer.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>
|
||||
@@ -0,0 +1,17 @@
|
||||
package _VisualDVM.ComponentsServer.Component.UI;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
113
src/_VisualDVM/ComponentsServer/Component/UI/ComponentsForm.java
Normal file
113
src/_VisualDVM/ComponentsServer/Component/UI/ComponentsForm.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package _VisualDVM.ComponentsServer.Component.UI;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.MainModule_;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Menus.VisualiserMenu;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import Common.Visual.Tables.RendererMaskedNanInteger;
|
||||
import Common.Visual.Tables.RendererStatusEnum;
|
||||
import _VisualDVM.ComponentsServer.Component.Component;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Vector;
|
||||
public class ComponentsForm extends DataSetControlForm<Component> {
|
||||
public ComponentsForm(DataSet<?, Component> dataSource_in, JPanel mountPanel_in) {
|
||||
super(dataSource_in, mountPanel_in);
|
||||
}
|
||||
@Override
|
||||
protected void createColumns() {
|
||||
AddColumns(
|
||||
new ColumnInfo<Component>("Компонент") {
|
||||
@Override
|
||||
public Object getFieldAt(Component object) {
|
||||
return object.getComponentType().getDescription();
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Component>("Текущая версия") {
|
||||
@Override
|
||||
public Object getFieldAt(Component object) {
|
||||
return object.version;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererMaskedNanInteger.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Component>("Актуальная версия") {
|
||||
@Override
|
||||
public Object getFieldAt(Component object) {
|
||||
return object.actual_version;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererMaskedNanInteger.class;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Component>("Дата сборки") {
|
||||
@Override
|
||||
public Object getFieldAt(Component object) {
|
||||
return object.date_text;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Component>("Статус") {
|
||||
@Override
|
||||
public Object getFieldAt(Component object) {
|
||||
return object.getState();
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return RendererStatusEnum.class;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription(), PassCode.InstallComponentFromFolder,
|
||||
PassCode.UpdateSelectedComponents,
|
||||
PassCode.PublishComponent,
|
||||
PassCode.ShowComponentChangesLog) {
|
||||
{
|
||||
addMenus(
|
||||
new VisualiserMenu(
|
||||
"Восстановление предыдущей версии компонента", "/icons/Resurrect.png") {
|
||||
{
|
||||
setFont(MainModule_.instance.getUI().getTheme().Fonts.get(VisualiserFonts.Menu));
|
||||
add(Global.mainModule.getPass(PassCode.ResurrectComponent).createMenuItem());
|
||||
add(Global.mainModule.getPass(PassCode.ResurrectComponentFromServer).createMenuItem());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public Vector<Component> getSelectedItems() {
|
||||
Vector<Component> target = new Vector<>();
|
||||
Component visualiser = null;
|
||||
Component server = null;
|
||||
//------------------------
|
||||
for (Component component : super.getSelectedItems()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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.ComponentsServer.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.ComponentsServer.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/ComponentsServer/Component/UI/PublishFields.form
Normal file
126
src/_VisualDVM/ComponentsServer/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.ComponentsServer.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>
|
||||
@@ -0,0 +1,34 @@
|
||||
package _VisualDVM.ComponentsServer.Component.UI;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
import _VisualDVM.Visual.Editor.BaseEditor;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package _VisualDVM.ComponentsServer.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;
|
||||
}
|
||||
}
|
||||
93
src/_VisualDVM/ComponentsServer/Component/Visualiser.java
Normal file
93
src/_VisualDVM/ComponentsServer/Component/Visualiser.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
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 = Constants.version;
|
||||
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() {
|
||||
File res = Global.ProjectsDirectory;
|
||||
//---
|
||||
if (!Global.normalProperties.Workspace.isEmpty()) {
|
||||
File workspace = new File(Global.normalProperties.Workspace);
|
||||
if (workspace.exists())
|
||||
res = workspace;
|
||||
else
|
||||
Global.mainModule.getPass(PassCode.UpdateProperty).Do("Workspace", "");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public File getDownloadsDirectory(){
|
||||
File res = new File(getWorkspace(), Constants.DownloadsDirectoryName);
|
||||
Utils_.CheckDirectory(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
135
src/_VisualDVM/ComponentsServer/Component/Visualizer_2.java
Normal file
135
src/_VisualDVM/ComponentsServer/Component/Visualizer_2.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package _VisualDVM.ComponentsServer.Component;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Utils;
|
||||
|
||||
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 {
|
||||
public String PID = "";
|
||||
//</editor-fold>
|
||||
//-
|
||||
//<editor-fold desc="функционал">
|
||||
int port;
|
||||
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 Utils_.getHomePath();
|
||||
}
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
try {
|
||||
Command("get_version: ");
|
||||
UnpackVersionInfo(this, response);
|
||||
} catch (Exception e) {
|
||||
Utils_.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) {
|
||||
Utils_.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void Update() throws Exception {
|
||||
super.Update();
|
||||
SendRequest("update_server: ");
|
||||
ReplaceOldFile();
|
||||
UI.Info("Сервер успешно обновлен.\n" +
|
||||
"Визуализатор завершает работу.\n" +
|
||||
"Для продолжения перезапустите визуализатор вручную.");
|
||||
System.exit(0);
|
||||
}
|
||||
@Override
|
||||
public String getAssemblyCommand() {
|
||||
File src_home= Paths.get(Global.RepoDirectory.getAbsolutePath(),"/sapfor/experts/Sapfor_2017/_src/Server").toFile();
|
||||
return "cd " +Utils_.DQuotes(src_home)+
|
||||
"\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 вернула " + Utils_.Brackets(response));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Print("<-" + response);
|
||||
out.flush();
|
||||
System.gc();
|
||||
return response;
|
||||
}
|
||||
//</editor-fold>
|
||||
}
|
||||
418
src/_VisualDVM/ComponentsServer/ComponentsServer.java
Normal file
418
src/_VisualDVM/ComponentsServer/ComponentsServer.java
Normal file
@@ -0,0 +1,418 @@
|
||||
package _VisualDVM.ComponentsServer;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.RepositoryRefuseException;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import _VisualDVM.ComponentsServer.BugReport.Json.BugReportAdditionJson;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.ComponentsServer.Component.Json.ComponentPublicationInfoJson;
|
||||
import _VisualDVM.ComponentsServer.Component.Json.ComponentVersionsInfoJson;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.Account;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import _VisualDVM.GlobalData.Machine.Machine;
|
||||
import _VisualDVM.GlobalData.Machine.MachineType;
|
||||
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
|
||||
import _VisualDVM.GlobalData.User.User;
|
||||
import _VisualDVM.Passes.All.ArchivesBackupPass;
|
||||
import _VisualDVM.Passes.All.UnzipFolderPass;
|
||||
import _VisualDVM.Passes.All.ZipFolderPass;
|
||||
import _VisualDVM.ProjectData.LanguageName;
|
||||
import _VisualDVM.Repository.EmailMessage;
|
||||
import _VisualDVM.Repository.Server.RepositoryServer;
|
||||
import _VisualDVM.Utils;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
public CredentialsDatabase credentials_db = null;
|
||||
//--
|
||||
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"))
|
||||
));
|
||||
//-
|
||||
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.componentsServerProperties.BackupHour) && (minute == Global.componentsServerProperties.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
|
||||
//todo оформить как у планировщика, так как это нить, напрямую сервер трогать нельзя.
|
||||
if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
|
||||
EmailMessage message = new EmailMessage("db backup", "копия баз данных журнала ошибок");
|
||||
message.addAttachement(db.getFile());
|
||||
for (String address : Constants.admins_mails) {
|
||||
Email(message, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------
|
||||
Thread.sleep(60000);
|
||||
} catch (Exception ex) {
|
||||
Utils_.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
public ComponentsServer() {
|
||||
super(BugReportsDatabase.class);
|
||||
}
|
||||
@Override
|
||||
public String getServerFileName() {
|
||||
return "VisualSapfor.jar";
|
||||
}
|
||||
@Override
|
||||
public String getServerHomeName() {
|
||||
return "_sapfor_x64";
|
||||
}
|
||||
@Override
|
||||
public int getPort() {
|
||||
return Constants.ComponentsServerPort;
|
||||
}
|
||||
@Override
|
||||
protected void beforePublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof BugReport) {
|
||||
BugReport bugReport = (BugReport) object;
|
||||
if (bugReport.packed_archive != null) {
|
||||
File bugArchive = Utils_.getFile(Utils_.getHomePath(), "Bugs", bugReport.id);
|
||||
Utils_.bytesToFile(bugReport.packed_archive, bugArchive);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void afterDeleteAction(DBObject object) throws Exception {
|
||||
if (object instanceof BugReport) {
|
||||
BugReport bugReport = (BugReport) object;
|
||||
if (!bugReport.project_version.isEmpty()) Utils_.forceDeleteWithCheck(bugReport.getArchiveFile());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void StartAction() throws Exception {
|
||||
if (Global.componentsServerProperties.EmailAdminsOnStart) {
|
||||
EmailMessage message = new EmailMessage("Сервер Sapfor запущен", new Date().toString());
|
||||
for (String address : Constants.admins_mails) {
|
||||
Email(message, address);
|
||||
}
|
||||
}
|
||||
//--
|
||||
try {
|
||||
credentials_db = new CredentialsDatabase();
|
||||
credentials_db.Activate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void startAdditionalThreads() {
|
||||
backUp.start();
|
||||
}
|
||||
//-
|
||||
void DVMConvertProject() throws Exception {
|
||||
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(), Utils_.getFileNameWithoutExtension(program) + ".DVMH." + (projectLanguage.equals(LanguageName.fortran) ? "f" : "c")).toFile();
|
||||
String command = Utils_.DQuotes(Constants.server_dvm_drv) + " " + projectLanguage.getDVMCompile() + "dv " + options + " " + Utils_.DQuotes(program.getName());
|
||||
//--
|
||||
File fileWorkspace = program.getParentFile();
|
||||
Process process = Utils.startScript(workspace, fileWorkspace, Utils_.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 = Utils_.fileToBytes(resultArchive);
|
||||
} else throw new RepositoryRefuseException("Внутренняя ошибка. Не удалось запаковать версию");
|
||||
//--
|
||||
} else throw new RepositoryRefuseException("Внутренняя ошибка. Не удалось распаковать проект");
|
||||
}
|
||||
void AppendBugReportField() throws Exception {
|
||||
BugReportAdditionJson transport = (BugReportAdditionJson) request.object;
|
||||
if (db.bugReports.containsKey(transport.id)) {
|
||||
BugReport actual = db.bugReports.get(transport.id);
|
||||
Field field = BugReport.class.getField(transport.fieldName);
|
||||
field.set(actual, field.get(actual) + "\n" + transport.textAddition);
|
||||
actual.change_date = new Date().getTime();
|
||||
db.Update(actual);
|
||||
response.object = actual;
|
||||
} else throw new RepositoryRefuseException("Баг репорт с ключом " + transport.id + " не существует.");
|
||||
}
|
||||
void ReceiveAllArchives() throws Exception {
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
File archives = new File(Utils_.getDateName("Bugs"));
|
||||
if (zip.Do("Bugs", archives.getAbsolutePath())) {
|
||||
response.object = Utils_.fileToBytes(archives);
|
||||
} else throw new RepositoryRefuseException("Не удалось запаковать архивы");
|
||||
}
|
||||
void ReceiveBugReportsDatabase() throws Exception{
|
||||
response.object = Utils_.fileToBytes(db.getFile());
|
||||
}
|
||||
void ReceiveBugReport() throws Exception {
|
||||
File bugArchive = Utils_.getFile(Utils_.getHomePath(), "Bugs", request.arg);
|
||||
response.object = Utils_.fileToBytes(bugArchive);
|
||||
}
|
||||
void UpdateBugReport() throws Exception {
|
||||
BugReport oldBugReport = (BugReport) request.object;
|
||||
if (db.bugReports.containsKey(oldBugReport.id)) {
|
||||
BugReport bugReport = db.bugReports.get(oldBugReport.id);
|
||||
bugReport.SynchronizeFields(oldBugReport);
|
||||
bugReport.change_date = new Date().getTime();
|
||||
db.Update(bugReport);
|
||||
} else
|
||||
throw new RepositoryRefuseException("Баг репорт с ключом " + oldBugReport.id + " не существует.");
|
||||
}
|
||||
//--
|
||||
void CheckSubscriberRole() throws Exception {
|
||||
Account account = (Account) request.object;
|
||||
Subscriber subscriber = null;
|
||||
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; //возвращаем информацию о подписчике.
|
||||
}
|
||||
void GetComponentsBackUps() throws Exception {
|
||||
File backupsDirectory = Paths.get(Utils_.getHomePath(), "Components", request.arg, "Backups").toFile();
|
||||
//--
|
||||
if (backupsDirectory.exists()) {
|
||||
File[] files = backupsDirectory.listFiles(File::isFile);
|
||||
if (files != null) {
|
||||
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.object = new Vector<>();
|
||||
}
|
||||
}
|
||||
void CheckURLRegistered() throws Exception {
|
||||
String[] data = request.arg.split("\n");
|
||||
String email = data[0];
|
||||
String machineURL = data[1];
|
||||
String login = data[2];
|
||||
response.object = db.workspaces.findWorkspace(email, machineURL, login);
|
||||
}
|
||||
void GetComponentChangesLog() throws Exception {
|
||||
response.object = Utils_.fileToBytes(Paths.get(Utils_.getHomePath(), "Components", request.arg, "changes.txt").toFile());
|
||||
}
|
||||
void PublishComponent() throws Exception {
|
||||
ComponentPublicationInfoJson info = (ComponentPublicationInfoJson) request.object;
|
||||
File componentHome = Utils_.getFile(Utils_.getHomePath(), "Components", info.componentType.toString());
|
||||
File componentFile = new File(componentHome, info.fileName);
|
||||
File versionFile = new File(componentHome, "version.txt");
|
||||
File backupsFolder = new File(componentHome, "Backups");
|
||||
//0 архивация старой версии, если она есть.
|
||||
if (componentFile.exists()) {
|
||||
String versionText = "";
|
||||
if (versionFile.exists()) versionText = Utils.ReadAllText(versionFile);
|
||||
//---->>
|
||||
Utils_.CheckDirectory(backupsFolder);
|
||||
Utils.keepNewFiles(backupsFolder, Global.componentsServerProperties.ComponentsBackUpsCount);
|
||||
//-->>
|
||||
File backupFile = new File(backupsFolder, info.componentType + "_" + versionText);
|
||||
if (backupFile.exists()) Utils_.forceDeleteWithCheck(backupFile);
|
||||
FileUtils.moveFile(componentFile, backupFile);
|
||||
}
|
||||
//1 распаковка компонента
|
||||
Utils_.bytesToFile((byte[]) info.packedFile, componentFile);
|
||||
//2 запись версии компонента
|
||||
FileUtils.writeStringToFile(versionFile, info.versionText);
|
||||
//3 запись в журнал компонента
|
||||
File changesLog = new File(componentHome, "changes.txt");
|
||||
FileWriter writer = new FileWriter(changesLog.getAbsolutePath(), true);
|
||||
BufferedWriter bufferWriter = new BufferedWriter(writer);
|
||||
bufferWriter.write(info.changeRecord);
|
||||
bufferWriter.close();
|
||||
//-
|
||||
if (info.needsUpdateMinimalVersion) {
|
||||
Print("Поднять минимальную версию компонента " + info.componentType);
|
||||
File minimal_versionFile = new File(componentHome, "minimal_version.txt");
|
||||
FileUtils.writeStringToFile(minimal_versionFile, info.versionText);
|
||||
//-
|
||||
//3 запись в журнал компонента
|
||||
FileWriter writer_ = new FileWriter(changesLog, true);
|
||||
BufferedWriter bufferWriter_ = new BufferedWriter(writer_);
|
||||
bufferWriter_.write("Минимальная версия поднята до " + info.versionText + "\n");
|
||||
bufferWriter_.close();
|
||||
}
|
||||
}
|
||||
void GetComponentsVersionsInfo() throws Exception {
|
||||
Vector<String> types = (Vector<String>) request.object;
|
||||
Vector<ComponentVersionsInfoJson> res = new Vector<>();
|
||||
for (String sType : types) {
|
||||
ComponentType componentType = ComponentType.valueOf(sType);
|
||||
File actualVersionFile = Paths.get(Utils_.getHomePath(), "Components", sType, "version.txt").toFile();
|
||||
File minimalVersionFile = Paths.get(Utils_.getHomePath(), "Components", sType, "minimal_version.txt").toFile();
|
||||
ComponentVersionsInfoJson info = new ComponentVersionsInfoJson(componentType);
|
||||
info.actual_version = Utils_.removeCharacters(Utils.ReadAllText(actualVersionFile), "\n", "\r");
|
||||
info.minimal_version = Utils_.removeCharacters(Utils.ReadAllText(minimalVersionFile), "\n", "\r");
|
||||
res.add(info);
|
||||
}
|
||||
response.object = res;
|
||||
}
|
||||
void ReceiveComponent() throws Exception {
|
||||
String[] packed1 = request.arg.split("\n");
|
||||
//тип/имя файла
|
||||
File componentFile1 = Paths.get(Utils_.getHomePath(), "Components", packed1[0], packed1[1]).toFile();
|
||||
Print("Получить компонент " + packed1[0]);
|
||||
response.object = Utils_.fileToBytes(componentFile1);
|
||||
}
|
||||
void GetUserAccountByKey() throws Exception {
|
||||
UserAccount account = credentials_db.userAccounts.getByKey(request.arg);
|
||||
response.object = account==null? null: account;
|
||||
}
|
||||
void GetUserAccountByEmail() throws Exception {
|
||||
UserAccount account_info = (UserAccount) request.object;
|
||||
UserAccount account = credentials_db.userAccounts.getByEmail(account_info.email);
|
||||
if (account==null){
|
||||
account = new UserAccount(account_info);
|
||||
account.role = Constants.admins_mails.contains(account.email)? AccountRole.Admin: AccountRole.User;
|
||||
account.security_key = RandomStringUtils.random(100, true, true);
|
||||
credentials_db.Insert(account);
|
||||
}
|
||||
response.object = account;
|
||||
}
|
||||
//--
|
||||
@Override
|
||||
protected void UnsafeSession() throws Exception {
|
||||
switch (code) {
|
||||
case GetUserAccountByKey:
|
||||
GetUserAccountByKey();
|
||||
break;
|
||||
case GetUserAccountByEmail:
|
||||
GetUserAccountByEmail();
|
||||
break;
|
||||
case CheckSubscriberRole: //todo устарело
|
||||
CheckSubscriberRole();
|
||||
break;
|
||||
case GetComponentsBackups:
|
||||
GetComponentsBackUps();
|
||||
break;
|
||||
case UpdateComponent:
|
||||
//возможно со стороны админа ввод подтверждения по почте запрашивать.
|
||||
PublishComponent();
|
||||
break;
|
||||
case ReceiveComponent:
|
||||
ReceiveComponent();
|
||||
break;
|
||||
case CheckURLRegistered:
|
||||
CheckURLRegistered();
|
||||
break;
|
||||
case GetComponentsVersionsInfo:
|
||||
GetComponentsVersionsInfo();
|
||||
break;
|
||||
case GetComponentChangesLog:
|
||||
GetComponentChangesLog();
|
||||
break;
|
||||
default:
|
||||
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void Session() throws Exception {
|
||||
switch (code) {
|
||||
case ReceiveAllArchives:
|
||||
ReceiveAllArchives();
|
||||
break;
|
||||
case UpdateBugReport:
|
||||
UpdateBugReport();
|
||||
break;
|
||||
case AppendBugReportTextField:
|
||||
AppendBugReportField();
|
||||
break;
|
||||
case ReceiveBugReportsDatabase:
|
||||
ReceiveBugReportsDatabase();
|
||||
break;
|
||||
case ReceiveBugReport:
|
||||
ReceiveBugReport();
|
||||
break;
|
||||
case DVMConvertProject:
|
||||
DVMConvertProject();
|
||||
break;
|
||||
default:
|
||||
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/_VisualDVM/ComponentsServer/CredentialsDatabase.java
Normal file
20
src/_VisualDVM/ComponentsServer/CredentialsDatabase.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package _VisualDVM.ComponentsServer;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import Common.Passes.PassCode_;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccountsDBTable;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
public class CredentialsDatabase extends SQLiteDatabase {
|
||||
public UserAccountsDBTable userAccounts;
|
||||
public CredentialsDatabase() {
|
||||
super(Paths.get(System.getProperty("user.dir"), "Data", "credentials.sqlite").toFile());
|
||||
}
|
||||
@Override
|
||||
protected void initAllTables() throws Exception {
|
||||
addTable(userAccounts = new UserAccountsDBTable());
|
||||
}
|
||||
@Override
|
||||
public PassCode_ getSynchronizePassCode() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package _VisualDVM.ComponentsServer.SubscriberRights;
|
||||
import Common.Database.Objects.DBObject;
|
||||
public class SubscriberRights extends DBObject {
|
||||
public String email; //почта
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package _VisualDVM.ComponentsServer.SubscriberWorkspace;
|
||||
import Common.Database.Objects.iDBObject;
|
||||
public class SubscriberWorkspace extends iDBObject {
|
||||
public String email; //почта
|
||||
public String URL; //адрес:порт машины
|
||||
public String login; // имя пользователя
|
||||
public String path; //рабочая папка на машине
|
||||
//-
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package _VisualDVM.ComponentsServer.SubscriberWorkspace;
|
||||
import Common.Database.Tables.iDBTable;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import _VisualDVM.ComponentsServer.SubscriberWorkspace.UI.SubscriberWorkspacesForm;
|
||||
|
||||
import javax.swing.*;
|
||||
public class SubscriberWorkspaceDBTable extends iDBTable<SubscriberWorkspace> {
|
||||
public SubscriberWorkspaceDBTable() {
|
||||
super(SubscriberWorkspace.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "рабочая папка";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "рабочие папки";
|
||||
}
|
||||
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
|
||||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||||
return new SubscriberWorkspacesForm(this, mountPanel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package _VisualDVM.ComponentsServer.SubscriberWorkspace.UI;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import _VisualDVM.ComponentsServer.SubscriberWorkspace.SubscriberWorkspace;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
import javax.swing.*;
|
||||
public class SubscriberWorkspacesForm extends DataSetControlForm<SubscriberWorkspace> {
|
||||
public SubscriberWorkspacesForm(DataSet<?, SubscriberWorkspace> dataSource_in, JPanel mountPanel_in) {
|
||||
super(dataSource_in, mountPanel_in);
|
||||
}
|
||||
@Override
|
||||
protected boolean isPKVisible() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void createColumns() {
|
||||
AddColumns(
|
||||
new ColumnInfo<SubscriberWorkspace>("URL") {
|
||||
@Override
|
||||
public Object getFieldAt(SubscriberWorkspace object) {
|
||||
return object.URL;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<SubscriberWorkspace>("пользователь") {
|
||||
@Override
|
||||
public Object getFieldAt(SubscriberWorkspace object) {
|
||||
return object.login;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<SubscriberWorkspace>("папка") {
|
||||
@Override
|
||||
public Object getFieldAt(SubscriberWorkspace object) {
|
||||
return object.path;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public PassCode_ getDeletePassCode() {
|
||||
return PassCode.DeleteSubscriberWorkspace;
|
||||
}
|
||||
@Override
|
||||
public DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription(), PassCode.DeleteSubscriberWorkspace);
|
||||
}
|
||||
@Override
|
||||
public boolean isObjectVisible(SubscriberWorkspace object) {
|
||||
Subscriber subscriber = Global.componentsServer.db.subscribers.getUI().getCurrent();
|
||||
return super.isObjectVisible(object) && (subscriber != null) && subscriber.address.equals(object.email) &&
|
||||
(Global.mainModule.getAccount().isAdmin() || Global.mainModule.getAccount().email.equals(subscriber.address));
|
||||
}
|
||||
}
|
||||
40
src/_VisualDVM/ComponentsServer/Subscribes/Subscriber.java
Normal file
40
src/_VisualDVM/ComponentsServer/Subscribes/Subscriber.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package _VisualDVM.ComponentsServer.Subscribes;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
public class Subscriber extends DBObject {
|
||||
//todo скорее всего вывести.ибо дублер UserAccount
|
||||
@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 "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package _VisualDVM.ComponentsServer.Subscribes;
|
||||
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 Common.Visual.DataSetControlForm;
|
||||
import _VisualDVM.ComponentsServer.SubscriberWorkspace.SubscriberWorkspace;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.UI.SubsribersForm;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public class SubsribersDBTable extends DBTable<String, Subscriber> {
|
||||
public SubsribersDBTable() {
|
||||
super(String.class, Subscriber.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "адресат";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "адресаты";
|
||||
}
|
||||
@Override
|
||||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||||
return new SubsribersForm(this, mountPanel);
|
||||
}
|
||||
@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;
|
||||
}
|
||||
public Vector<String> getActiveSubscribers(){
|
||||
Vector<String> res = new Vector<>();
|
||||
for (Subscriber subscriber : Data.values()) {
|
||||
if ((subscriber.mailOn != 0) && !res.contains(subscriber.address))
|
||||
res.add(subscriber.address);
|
||||
}
|
||||
for (String admin_mail : Constants.admins_mails) {
|
||||
if (!res.contains(admin_mail))
|
||||
res.add(admin_mail);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public Vector<String> checkRecipients(Vector<String> recipients){
|
||||
Vector<String> res = new Vector<>();
|
||||
for (String address: recipients){
|
||||
if (this.containsKey(address) && get(address).mailOn!=0){
|
||||
res.add(address);
|
||||
}
|
||||
}
|
||||
//--
|
||||
if (!res.contains(Global.mainModule.getAccount().email))
|
||||
res.add(Global.mainModule.getAccount().email);
|
||||
//--
|
||||
for (String admin_mail : Constants.admins_mails) {
|
||||
if (!res.contains(admin_mail))
|
||||
res.add(admin_mail);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package _VisualDVM.ComponentsServer.Subscribes.UI;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
public class SubscriberDialog extends DBObjectDialog<Subscriber, SubscriberFields> {
|
||||
public SubscriberDialog() {
|
||||
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("Имя учётной записи не может быть пустым");
|
||||
Utils_.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_("Адрес электронной почты " + Utils_.Brackets(fields.tfAddress.getText()) + " уже есть в списке.");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void fillFields() {
|
||||
fields.tfName.setText(Result.name);
|
||||
fields.tfAddress.setText(Result.address);
|
||||
fields.cbMail.setSelected(Result.mailOn != 0);
|
||||
UI.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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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.ComponentsServer.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="Common/icons/NotPick.png"/>
|
||||
<selectedIcon value="Common/icons/Pick.png"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Будет ли включена рассылка для этого пользователя"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,27 @@
|
||||
package _VisualDVM.ComponentsServer.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 {
|
||||
public JTextField tfName;
|
||||
public JTextField tfAddress;
|
||||
public JComboBox<AccountRole> cbRole;
|
||||
public JCheckBox cbMail;
|
||||
private JPanel content;
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package _VisualDVM.ComponentsServer.Subscribes.UI;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
import javax.swing.*;
|
||||
public class SubsribersForm extends DataSetControlForm<Subscriber> {
|
||||
public SubsribersForm(DataSet<?, Subscriber> dataSource_in, JPanel mountPanel_in) {
|
||||
super(dataSource_in, mountPanel_in);
|
||||
}
|
||||
@Override
|
||||
protected ColumnInfo<Subscriber> createPKColumn() {
|
||||
return new ColumnInfo<Subscriber>(dataSource.getPKName()) {
|
||||
@Override
|
||||
public Object getFieldAt(Subscriber object) {
|
||||
return object.getPK();
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Global.mainModule.getAccount().role.equals(AccountRole.Admin);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
protected void createColumns() {
|
||||
AddColumns(
|
||||
new ColumnInfo<Subscriber>("Имя") {
|
||||
@Override
|
||||
public Object getFieldAt(Subscriber object) {
|
||||
return object.name;
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Subscriber>("Роль") {
|
||||
@Override
|
||||
public Object getFieldAt(Subscriber object) {
|
||||
return object.role.getDescription();
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Global.mainModule.getAccount().role.equals(AccountRole.Admin);
|
||||
}
|
||||
},
|
||||
new ColumnInfo<Subscriber>("Рассылка") {
|
||||
@Override
|
||||
public Object getFieldAt(Subscriber object) {
|
||||
return (object.mailOn == 0) ? "выключена" : "включена";
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return Global.mainModule.getAccount().role.equals(AccountRole.Admin);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public PassCode_ getDeletePassCode() {
|
||||
return PassCode.DeleteSubscriber;
|
||||
}
|
||||
@Override
|
||||
public DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription(),
|
||||
PassCode.SaveBugReportExecutor,
|
||||
PassCode.SaveBugReportRecipients,
|
||||
PassCode.AddSubscriber,
|
||||
PassCode.EditSubscriber,
|
||||
PassCode.DeleteSubscriber);
|
||||
}
|
||||
@Override
|
||||
protected DBObjectDialog<Subscriber, ? extends DialogFields> getDialog() {
|
||||
return new SubscriberDialog();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package _VisualDVM.ComponentsServer.UserAccount.UI;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
public class UserAccountDialog extends DBObjectDialog<UserAccount, UserAccountFields> {
|
||||
public UserAccountDialog() {
|
||||
super(UserAccountFields.class);
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 250;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 450;
|
||||
}
|
||||
@Override
|
||||
public void validateFields() {
|
||||
if (fields.tfName.getText().isEmpty())
|
||||
Log.Writeln("Имя учётной записи не может быть пустым");
|
||||
Utils_.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_("Адрес электронной почты " + Utils_.Brackets(fields.tfAddress.getText()) + " уже есть в списке.");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void fillFields() {
|
||||
fields.tfName.setText(Result.name);
|
||||
fields.tfAddress.setText(Result.email);
|
||||
fields.cbMail.setSelected(Result.subscribe_active != 0);
|
||||
UI.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.email = fields.tfAddress.getText();
|
||||
Result.subscribe_active = fields.cbMail.isSelected() ? 1 : 0;
|
||||
Result.role = getSelectedRole();
|
||||
}
|
||||
};
|
||||
@@ -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.ComponentsServer.UserAccount.UI.UserAccountFields">
|
||||
<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="5e1da" 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="de3f0">
|
||||
<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="e0e31" 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="c014a" 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="2761d" 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="15e49" 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="4da2" 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="Common/icons/NotPick.png"/>
|
||||
<selectedIcon value="Common/icons/Pick.png"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Будет ли включена рассылка для этого пользователя"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="398ee" 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="34bef" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,27 @@
|
||||
package _VisualDVM.ComponentsServer.UserAccount.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 UserAccountFields implements DialogFields {
|
||||
private JPanel content;
|
||||
public JTextField tfName;
|
||||
public JTextField tfAddress;
|
||||
public JCheckBox cbMail;
|
||||
public JComboBox cbRole;
|
||||
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);
|
||||
}
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
30
src/_VisualDVM/ComponentsServer/UserAccount/UserAccount.java
Normal file
30
src/_VisualDVM/ComponentsServer/UserAccount/UserAccount.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package _VisualDVM.ComponentsServer.UserAccount;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Objects.iDBObject;
|
||||
import _VisualDVM.GlobalData.Account.AccountRole;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
public class UserAccount extends iDBObject {
|
||||
public String name = "";
|
||||
public String email = "";
|
||||
@Description("DEFAULT 1")
|
||||
public int subscribe_active = 1;
|
||||
public String security_key = "";
|
||||
@Description("DEFAULT 'User'")
|
||||
public AccountRole role = AccountRole.User; //права доступа
|
||||
public UserAccount(){
|
||||
|
||||
}
|
||||
public UserAccount(UserAccount account_in) {
|
||||
this.SynchronizeFields(account_in);
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
UserAccount src_ = (UserAccount) src;
|
||||
name = src_.name;
|
||||
email = src_.email;
|
||||
subscribe_active=src_.subscribe_active;
|
||||
security_key = src_.security_key;
|
||||
role = src_.role;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package _VisualDVM.ComponentsServer.UserAccount;
|
||||
import Common.Database.Tables.iDBTable;
|
||||
public class UserAccountsDBTable extends iDBTable<UserAccount> {
|
||||
public UserAccountsDBTable() {
|
||||
super(UserAccount.class);
|
||||
}
|
||||
public UserAccount getByKey(String key_in){
|
||||
for (UserAccount userAccount: Data.values()){
|
||||
if (userAccount.security_key.equals(key_in))
|
||||
return userAccount;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public UserAccount getByEmail(String email_in){
|
||||
for (UserAccount userAccount: Data.values()){
|
||||
if (userAccount.email.equals(email_in))
|
||||
return userAccount;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user