Skip to content

Commit 3760ed0

Browse files
committed
Fixes
- Disable ssl for setupLocalRepo - Reactivation of the confirmation message - Fixed file cleanup during export gateway
1 parent 36c50f1 commit 3760ed0

File tree

4 files changed

+114
-91
lines changed

4 files changed

+114
-91
lines changed

git-designer/src/main/java/com/axone_io/ignition/git/actions/GitBaseAction.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.axone_io.ignition.git.actions;
22

3-
import java.awt.event.ActionEvent;
4-
import java.util.List;
5-
import javax.swing.Icon;
6-
73
import com.axone_io.ignition.git.utils.IconUtils;
84
import com.inductiveautomation.ignition.client.util.action.BaseAction;
95
import com.inductiveautomation.ignition.client.util.gui.ErrorUtil;
6+
import com.inductiveautomation.ignition.common.BundleUtil;
107
import org.slf4j.Logger;
118
import org.slf4j.LoggerFactory;
129

13-
import static com.axone_io.ignition.git.DesignerHook.projectName;
14-
import static com.axone_io.ignition.git.DesignerHook.rpc;
15-
import static com.axone_io.ignition.git.DesignerHook.userName;
10+
import javax.swing.*;
11+
import java.awt.event.ActionEvent;
12+
import java.util.List;
13+
14+
import static com.axone_io.ignition.git.DesignerHook.*;
1615
import static com.axone_io.ignition.git.managers.GitActionManager.showCommitPopup;
16+
import static com.axone_io.ignition.git.managers.GitActionManager.showConfirmPopup;
1717

1818
public class GitBaseAction extends BaseAction {
1919
private static final Logger logger = LoggerFactory.getLogger(GitBaseAction.class);
@@ -63,14 +63,22 @@ public void actionPerformed(ActionEvent e) {
6363

6464
// Todo : Find a way to refactor with handleAction
6565
public static void handleCommitAction(List<String> changes, String commitMessage) {
66+
String message = BundleUtil.get().getStringLenient(GitActionType.COMMIT.baseBundleKey + ".ConfirmMessage");
67+
int messageType = JOptionPane.INFORMATION_MESSAGE;
68+
6669
try {
6770
rpc.commit(projectName, userName, changes, commitMessage);
71+
SwingUtilities.invokeLater(new Thread(() -> showConfirmPopup(message, messageType)));
6872
} catch (Exception ex) {
6973
ErrorUtil.showError(ex);
7074
}
7175
}
7276

7377
public static void handleAction(GitActionType type) {
78+
String message = BundleUtil.get().getStringLenient(type.baseBundleKey + ".ConfirmMessage");
79+
int messageType = JOptionPane.INFORMATION_MESSAGE;
80+
boolean confirmPopup = Boolean.TRUE;
81+
7482
try {
7583
switch (type) {
7684
case PULL:
@@ -80,12 +88,15 @@ public static void handleAction(GitActionType type) {
8088
rpc.push(projectName, userName);
8189
break;
8290
case COMMIT:
91+
confirmPopup = Boolean.FALSE;
8392
showCommitPopup(projectName, userName);
8493
break;
8594
case EXPORT:
8695
rpc.exportConfig(projectName);
8796
break;
8897
}
98+
if(confirmPopup) SwingUtilities.invokeLater(new Thread(() -> showConfirmPopup(message, messageType)));
99+
89100
} catch (Exception ex) {
90101
ErrorUtil.showError(ex);
91102
}

git-designer/src/main/java/com/axone_io/ignition/git/managers/GitActionManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.axone_io.ignition.git.managers;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
import com.axone_io.ignition.git.CommitPopup;
74
import com.axone_io.ignition.git.DesignerHook;
85
import com.inductiveautomation.ignition.common.Dataset;
96
import com.inductiveautomation.ignition.common.project.ChangeOperation;
107
import com.inductiveautomation.ignition.common.project.resource.ProjectResourceId;
118

9+
import javax.swing.*;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
1213
import static com.axone_io.ignition.git.DesignerHook.context;
1314
import static com.axone_io.ignition.git.DesignerHook.rpc;
1415
import static com.axone_io.ignition.git.actions.GitBaseAction.handleCommitAction;
@@ -45,4 +46,9 @@ public void onActionPerformed(List<String> changes, String commitMessage) {
4546
}
4647
};
4748
}
49+
50+
public static void showConfirmPopup(String message, int messageType){
51+
JOptionPane.showConfirmDialog(context.getFrame(),
52+
message, "Info", JOptionPane.DEFAULT_OPTION, messageType);
53+
}
4854
}

git-gateway/src/main/java/com/axone_io/ignition/git/GatewayScriptModule.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
package com.axone_io.ignition.git;
22

3-
import java.nio.file.Files;
4-
import java.nio.file.Path;
5-
import java.util.ArrayList;
6-
import java.util.List;
7-
import java.util.Set;
8-
93
import com.axone_io.ignition.git.records.GitProjectsConfigRecord;
104
import com.inductiveautomation.ignition.common.BasicDataset;
115
import com.inductiveautomation.ignition.common.Dataset;
126
import com.inductiveautomation.ignition.common.util.DatasetBuilder;
137
import com.inductiveautomation.ignition.common.util.LoggerEx;
148
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
15-
import org.eclipse.jgit.api.Git;
16-
import org.eclipse.jgit.api.PullCommand;
17-
import org.eclipse.jgit.api.PullResult;
18-
import org.eclipse.jgit.api.PushCommand;
19-
import org.eclipse.jgit.api.Status;
9+
import org.eclipse.jgit.api.*;
2010
import org.eclipse.jgit.api.errors.GitAPIException;
2111
import org.eclipse.jgit.transport.PushResult;
2212
import org.eclipse.jgit.transport.RefSpec;
2313
import org.eclipse.jgit.transport.URIish;
2414

25-
import static com.axone_io.ignition.git.managers.GitManager.exportImages;
26-
import static com.axone_io.ignition.git.managers.GitManager.exportTag;
27-
import static com.axone_io.ignition.git.managers.GitManager.exportTheme;
28-
import static com.axone_io.ignition.git.managers.GitManager.getGit;
29-
import static com.axone_io.ignition.git.managers.GitManager.getGitProjectConfigRecord;
30-
import static com.axone_io.ignition.git.managers.GitManager.getGitReposUserRecord;
31-
import static com.axone_io.ignition.git.managers.GitManager.setAuthentication;
32-
import static com.axone_io.ignition.git.managers.GitManager.uncommittedChangesBuilder;
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
import java.util.Set;
20+
21+
import static com.axone_io.ignition.git.managers.GitManager.*;
3322

3423
public class GatewayScriptModule extends AbstractScriptModule {
3524
private final LoggerEx logger = LoggerEx.newBuilder().build(getClass());
@@ -160,18 +149,23 @@ public void setupLocalRepoImpl(String projectName, String userName) throws Excep
160149
Path projectFolderPath = getProjectFolderPath(projectName);
161150
GitProjectsConfigRecord gitProjectsConfigRecord = getGitProjectConfigRecord(projectName);
162151

163-
Path path = projectFolderPath.resolve(".git");
164-
if (!Files.exists(path)) {
165-
PushCommand pushCommand;
166-
try (Git git = Git.init().setDirectory(projectFolderPath.toFile()).call()) {
152+
if (!Files.exists(projectFolderPath.resolve(".git"))) {
153+
try{
154+
Git git = Git.init().setDirectory(projectFolderPath.toFile()).call();
155+
disableSsl(git);
156+
167157
git.remoteAdd().setName("origin").setUri(new URIish(gitProjectsConfigRecord.getURI())).call();
168158

169159
git.add().addFilepattern(".").call();
170160
git.commit().setMessage("Initial commit").call();
171-
pushCommand = git.push();
161+
PushCommand pushCommand = git.push();
162+
163+
setAuthentication(pushCommand, projectName, userName);
164+
pushCommand.setRemote("origin").setRefSpecs(new RefSpec("master")).call();
165+
}catch (Exception e){
166+
logger.warn("An error occurred while setting up local repo for '" + projectName + "' project.");
167+
throw new RuntimeException(e);
172168
}
173-
setAuthentication(pushCommand, projectName, userName);
174-
pushCommand.setRemote("origin").setRefSpecs(new RefSpec("master")).call();
175169
}
176170
}
177171

git-gateway/src/main/java/com/axone_io/ignition/git/managers/GitManager.java

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package com.axone_io.ignition.git.managers;
22

3-
import java.io.IOException;
4-
import java.nio.file.Files;
5-
import java.nio.file.Path;
6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.List;
9-
import java.util.Set;
10-
import java.util.concurrent.CompletableFuture;
11-
123
import com.axone_io.ignition.git.SshTransportConfigCallback;
134
import com.axone_io.ignition.git.records.GitProjectsConfigRecord;
145
import com.axone_io.ignition.git.records.GitReposUsersRecord;
156
import com.inductiveautomation.ignition.common.JsonUtilities;
167
import com.inductiveautomation.ignition.common.gson.Gson;
17-
import com.inductiveautomation.ignition.common.gson.GsonBuilder;
188
import com.inductiveautomation.ignition.common.gson.JsonElement;
199
import com.inductiveautomation.ignition.common.gson.JsonObject;
2010
import com.inductiveautomation.ignition.common.project.RuntimeProject;
21-
import com.inductiveautomation.ignition.common.project.resource.*;
11+
import com.inductiveautomation.ignition.common.project.resource.LastModification;
12+
import com.inductiveautomation.ignition.common.project.resource.ProjectResource;
13+
import com.inductiveautomation.ignition.common.project.resource.ResourcePath;
14+
import com.inductiveautomation.ignition.common.project.resource.ResourceType;
2215
import com.inductiveautomation.ignition.common.tags.TagUtilities;
2316
import com.inductiveautomation.ignition.common.tags.config.TagConfigurationModel;
2417
import com.inductiveautomation.ignition.common.tags.model.TagPath;
@@ -36,24 +29,25 @@
3629
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
3730
import simpleorm.dataset.SQuery;
3831

32+
import java.io.IOException;
33+
import java.nio.file.Files;
34+
import java.nio.file.Path;
35+
import java.util.ArrayList;
36+
import java.util.Arrays;
37+
import java.util.List;
38+
import java.util.Set;
39+
import java.util.concurrent.CompletableFuture;
40+
3941
import static com.axone_io.ignition.git.GatewayHook.context;
4042

4143
public class GitManager {
4244
private final static LoggerEx logger = LoggerEx.newBuilder().build(GitManager.class);
4345

44-
private static final Gson PROJECT_GSON = new GsonBuilder()
45-
.registerTypeAdapter(ImmutableProjectResource.class, new ImmutableProjectResource.GsonAdapter())
46-
.registerTypeAdapter(byte[].class, new JsonUtilities.ByteArrayAdapter())
47-
.setPrettyPrinting()
48-
.create();
49-
5046
public static Git getGit(Path projectFolderPath) {
5147
Git git;
5248
try {
5349
git = Git.open(projectFolderPath.resolve(".git").toFile());
54-
StoredConfig config = git.getRepository().getConfig();
55-
config.setBoolean("http", null, "sslVerify", false);
56-
config.save();
50+
disableSsl(git);
5751
} catch (IOException e) {
5852
logger.error("Unable to retrieve Git repository", e);
5953
throw new RuntimeException(e);
@@ -71,7 +65,9 @@ public static void clearDirectory(Path folderPath) {
7165

7266
public static void exportTag(Path projectFolderPath) {
7367
Path tagFolderPath = projectFolderPath.resolve("tags");
74-
clearDirectory(tagFolderPath);
68+
if (tagFolderPath.toFile().exists()) {
69+
clearDirectory(tagFolderPath);
70+
}
7571

7672
try {
7773
Files.createDirectories(tagFolderPath);
@@ -82,7 +78,7 @@ public static void exportTag(Path projectFolderPath) {
8278
tagPaths.add(typesPath);
8379

8480
CompletableFuture<List<TagConfigurationModel>> cfTagModels =
85-
tagProvider.getTagConfigsAsync(tagPaths, true, true);
81+
tagProvider.getTagConfigsAsync(tagPaths, true, true);
8682
List<TagConfigurationModel> tModels = cfTagModels.get();
8783

8884
JsonObject json = TagUtilities.toJsonObject(tModels.get(0));
@@ -99,36 +95,45 @@ public static void exportTag(Path projectFolderPath) {
9995
}
10096

10197
public static void exportTheme(Path projectFolderPath) {
102-
try {
103-
Path sessionPropsPath = projectFolderPath.resolve("com.inductiveautomation.perspective")
104-
.resolve("session-props")
105-
.resolve("props.json");
106-
String content = Files.readString(sessionPropsPath);
107-
Gson g = new Gson();
108-
JsonObject json = g.fromJson(content, JsonObject.class);
109-
String theme = JsonUtilities.readString(json, "props.theme", "light");
110-
111-
Path themesDir = context.getSystemManager().getDataDir().toPath()
112-
.resolve("modules")
113-
.resolve("com.inductiveautomation.perspective")
114-
.resolve("themes");
115-
116-
Path themeFolder = themesDir.resolve(theme);
117-
Path themeFile = themesDir.resolve(theme + ".css");
118-
119-
Path themeFolderPath = projectFolderPath.resolve("themes");
98+
Path themeFolderPath = projectFolderPath.resolve("themes");
99+
if (themeFolderPath.toFile().exists()) {
120100
clearDirectory(themeFolderPath);
121-
Files.createDirectories(themeFolderPath);
122-
FileUtils.copyDirectoryToDirectory(themeFolder.toFile(), themeFolderPath.toFile());
123-
Files.copy(themeFile, themeFolderPath.resolve(themeFile.getFileName()));
101+
}
102+
try {
103+
Path perspectiveFolderPath = projectFolderPath.resolve("com.inductiveautomation.perspective");
104+
105+
if (perspectiveFolderPath.toFile().exists()) {
106+
Path sessionPropsPath = perspectiveFolderPath
107+
.resolve("session-props")
108+
.resolve("props.json");
109+
String content = Files.readString(sessionPropsPath);
110+
Gson g = new Gson();
111+
JsonObject json = g.fromJson(content, JsonObject.class);
112+
String theme = JsonUtilities.readString(json, "props.theme", "light");
113+
114+
Path themesDir = context.getSystemManager().getDataDir().toPath()
115+
.resolve("modules")
116+
.resolve("com.inductiveautomation.perspective")
117+
.resolve("themes");
118+
119+
Path themeFolder = themesDir.resolve(theme);
120+
Path themeFile = themesDir.resolve(theme + ".css");
121+
122+
Files.createDirectories(themeFolderPath);
123+
FileUtils.copyDirectoryToDirectory(themeFolder.toFile(), themeFolderPath.toFile());
124+
Files.copy(themeFile, themeFolderPath.resolve(themeFile.getFileName()));
125+
}
124126
} catch (IOException e) {
125127
logger.error(e.toString(), e);
126128
}
127129
}
128130

129131
public static void exportImages(Path projectFolderPath) {
130132
Path imageFolderPath = projectFolderPath.resolve("images");
131-
clearDirectory(imageFolderPath);
133+
if (imageFolderPath.toFile().exists()) {
134+
clearDirectory(imageFolderPath);
135+
}
136+
132137
try {
133138
Files.createDirectories(imageFolderPath);
134139
} catch (IOException e) {
@@ -151,7 +156,7 @@ public static void saveFolderImage(Path folderPath, String directory) {
151156
} else {
152157
byte[] data = imageManager.getImage(path).getBytes(ImageRecord.Data);
153158
try {
154-
Files.write(folderPath.resolve(path), data );
159+
Files.write(folderPath.resolve(path), data);
155160
} catch (IOException e) {
156161
logger.error(e.toString(), e);
157162
}
@@ -160,7 +165,7 @@ public static void saveFolderImage(Path folderPath, String directory) {
160165
}
161166

162167
public static void setAuthentication(TransportCommand<?, ?> command, String projectName, String userName)
163-
throws Exception {
168+
throws Exception {
164169
GitProjectsConfigRecord gitProjectsConfigRecord = getGitProjectConfigRecord(projectName);
165170
GitReposUsersRecord user = getGitReposUserRecord(gitProjectsConfigRecord, userName);
166171

@@ -173,7 +178,7 @@ public static void setAuthentication(TransportCommand<?, ?> command, String proj
173178

174179
public static GitProjectsConfigRecord getGitProjectConfigRecord(String projectName) throws Exception {
175180
SQuery<GitProjectsConfigRecord> projectQuery = new SQuery<>(GitProjectsConfigRecord.META)
176-
.eq(GitProjectsConfigRecord.ProjectName, projectName);
181+
.eq(GitProjectsConfigRecord.ProjectName, projectName);
177182
GitProjectsConfigRecord gitProjectsConfigRecord = context.getPersistenceInterface().queryOne(projectQuery);
178183

179184
if (gitProjectsConfigRecord == null) {
@@ -186,8 +191,8 @@ public static GitProjectsConfigRecord getGitProjectConfigRecord(String projectNa
186191
public static GitReposUsersRecord getGitReposUserRecord(GitProjectsConfigRecord gitProjectsConfigRecord,
187192
String userName) throws Exception {
188193
SQuery<GitReposUsersRecord> userQuery = new SQuery<>(GitReposUsersRecord.META)
189-
.eq(GitReposUsersRecord.ProjectId, gitProjectsConfigRecord.getId())
190-
.eq(GitReposUsersRecord.IgnitionUser, userName);
194+
.eq(GitReposUsersRecord.ProjectId, gitProjectsConfigRecord.getId())
195+
.eq(GitReposUsersRecord.IgnitionUser, userName);
191196
GitReposUsersRecord user = context.getPersistenceInterface().queryOne(userQuery);
192197

193198
if (user == null) {
@@ -244,25 +249,32 @@ public static boolean hasActor(String resource) {
244249

245250
public static String getActor(String projectName, String path) {
246251
ProjectManager projectManager = context.getProjectManager();
247-
RuntimeProject project =projectManager.getProject(projectName).get();
252+
RuntimeProject project = projectManager.getProject(projectName).get();
248253

249254
ProjectResource projectResource = project.getResource(getResourcePath(path)).get();
250-
String actor = LastModification.of(projectResource).map(LastModification::getActor).orElse("unknown");;
255+
String actor = LastModification.of(projectResource).map(LastModification::getActor).orElse("unknown");
256+
;
251257

252258
return actor;
253259
}
254260

255261

256-
public static ResourcePath getResourcePath(String resourcePath){
262+
public static ResourcePath getResourcePath(String resourcePath) {
257263
String moduleId = "";
258264
String typeId = "";
259265
String resource = "";
260266
String[] paths = resourcePath.split("/");
261267

262-
if (paths.length >0) moduleId = paths[0];
263-
if (paths.length >1) typeId = paths[1];
264-
if (paths.length >2) resource = resourcePath.replace(moduleId + "/" + typeId + "/", "");
268+
if (paths.length > 0) moduleId = paths[0];
269+
if (paths.length > 1) typeId = paths[1];
270+
if (paths.length > 2) resource = resourcePath.replace(moduleId + "/" + typeId + "/", "");
265271

266272
return new ResourcePath(new ResourceType(moduleId, typeId), resource);
267273
}
274+
275+
public static void disableSsl(Git git) throws IOException {
276+
StoredConfig config = git.getRepository().getConfig();
277+
config.setBoolean("http", null, "sslVerify", false);
278+
config.save();
279+
}
268280
}

0 commit comments

Comments
 (0)