From 8bcb61cea1194d4cb99a9c286b725612145840e8 Mon Sep 17 00:00:00 2001 From: "Galey, Charles E" Date: Mon, 29 Jun 2020 16:19:57 +0000 Subject: [PATCH 01/11] Propagate necessary changes for LMCO features --- .../java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java | 4 +- .../mbee/mdk/actions/MMSViewLinkAction.java | 2 +- .../mbee/mdk/cli/AutomatedViewGenerator.java | 7 +- .../nasa/jpl/mbee/mdk/docgen/DocGenUtils.java | 14 ++- .../nasa/jpl/mbee/mdk/emf/EMFExporter.java | 2 +- .../generator/ViewPresentationGenerator.java | 12 +- .../gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java | 78 ++++++++++--- .../mdk/mms/actions/CommitBranchAction.java | 8 +- .../actions/CommitClientElementAction.java | 8 +- .../actions/CommitDiagramArtifactsAction.java | 6 +- .../mbee/mdk/mms/actions/CommitOrgAction.java | 8 +- .../mdk/mms/actions/CommitProjectAction.java | 10 +- .../jpl/mbee/mdk/mms/actions/ExportImage.java | 6 +- .../mbee/mdk/mms/actions/MMSLoginAction.java | 6 +- .../mdk/mms/sync/delta/DeltaSyncRunner.java | 14 ++- .../mdk/mms/sync/manual/ManualSyncRunner.java | 12 +- .../MMSDeltaProjectEventListenerAdapter.java | 8 +- .../sync/status/actions/SyncStatusAction.java | 6 +- .../mdk/mms/validation/BranchValidator.java | 6 +- .../mdk/mms/validation/DiagramValidator.java | 22 +++- .../mdk/mms/validation/ElementValidator.java | 1 + .../mdk/mms/validation/ProjectValidator.java | 6 +- .../gov/nasa/jpl/mbee/mdk/util/MDUtils.java | 43 +++++++ .../nasa/jpl/mbee/mdk/util/TicketUtils.java | 8 +- .../gov/nasa/jpl/mbee/mdk/util/XMLUtil.java | 26 +++++ .../framework/MagicDrawClassLoaderWorker.java | 108 +++--------------- 26 files changed, 280 insertions(+), 151 deletions(-) create mode 100644 src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java b/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java index 6262d3e52..fd1426155 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java @@ -13,11 +13,10 @@ import com.nomagic.magicdraw.plugins.PluginUtils; import com.nomagic.magicdraw.uml.DiagramDescriptor; import com.nomagic.magicdraw.uml.DiagramTypeConstants; -import gov.nasa.jpl.mbee.mdk.cli.AutomatedCommitter; -import gov.nasa.jpl.mbee.mdk.cli.AutomatedViewGenerator; import gov.nasa.jpl.mbee.mdk.mms.sync.status.SyncStatusConfigurator; import gov.nasa.jpl.mbee.mdk.options.MDKOptionsGroup; import gov.nasa.jpl.mbee.mdk.util.MDUtils; +import gov.nasa.jpl.mbee.mdk.cli.AutomatedViewGenerator; import java.io.File; import java.lang.reflect.Method; @@ -82,7 +81,6 @@ public void init() { EvaluationConfigurator.getInstance().registerBinaryImplementers(this.getClass().getClassLoader()); CommandLineActionManager.getInstance().addAction(new AutomatedViewGenerator()); - CommandLineActionManager.getInstance().addAction(new AutomatedCommitter()); MDKConfigurator mdkConfigurator = new MDKConfigurator(); acm.addMainMenuConfigurator(mdkConfigurator); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java index cc049b88b..a459dd30b 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java @@ -58,7 +58,7 @@ public void actionPerformed(ActionEvent e) { //projects/PROJECT-ID_5_17_16_1_31_54_PM_5fc737b6_154bba92ecd_4cc1_cae_tw_jpl_nasa_gov_127_0_0_1/master/documents/_18_5_83a025f_1491339810716_846504_4332/views/_18_5_83a025f_1491339810716_846504_4332 // include this in the host portion of the uri. not technically correct, but it prevents the # from being converted and breaking things - uriBase.setHost(uriBase.getHost() + "/alfresco/mmsapp/mms.html#"); + uriBase.setHost(uriBase.getHost() + "/#"); uriBase.setPath(""); String uriPath; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java index 3b2b5ca8d..92b809728 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java @@ -32,7 +32,10 @@ import java.io.*; import java.net.HttpURLConnection; import java.net.URISyntaxException; -import java.rmi.RemoteException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -266,7 +269,7 @@ private void loadTeamworkProject() throws IOException, URISyntaxException, Inter mmsRefUri.setParameter("alf_ticket", ticketStore).setPath(mmsRefUri.getPath() + "/" + parser.getOptionValue(REF_ID)); MMSUtils.sendMMSRequest(null, MMSUtils.buildRequest(MMSUtils.HttpRequestType.GET, mmsRefUri), null, refsNode); } - } catch (IOException | ServerException e) { + } catch (IOException | ServerException | KeyStoreException | CertificateException | NoSuchAlgorithmException | KeyManagementException e) { illegalStateFailure("[FAILURE] Unable to load project, exception occurred while resolving one of the required project URI parameters."); e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java index e4303bac5..e782cafe5 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java @@ -12,11 +12,13 @@ import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import gov.nasa.jpl.mbee.mdk.docgen.docbook.DocumentElement; import gov.nasa.jpl.mbee.mdk.docgen.view.ViewElement; +import gov.nasa.jpl.mbee.mdk.util.MDUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; +import javax.xml.transform.TransformerException; import java.io.*; import java.util.*; import java.util.regex.Matcher; @@ -423,7 +425,7 @@ public static String html2docbook(String html) { * @throws IOException */ public static List exportDiagram(Diagram diagram, File directory) throws IOException { - int dpi = 72; + int dpi = Application.getInstance().getEnvironmentOptions().getGeneralOptions().getImageResolutionDpi(); int scalePercent = 100; Project project = Application.getInstance().getProject(); if (project == null) { @@ -435,6 +437,12 @@ public static List exportDiagram(Diagram diagram, File directory) throws return Collections.emptyList(); } + System.setProperty("svg.enriched.export", Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); + + Application.getInstance().getGUILog().log("[INFO] Generating Diagram of type" + diagramPresentationElement.getDiagramType().getRootType() + "."); + + + String pngFileName = diagramPresentationElement.getID() + ".png"; String svgFileName = diagramPresentationElement.getID() + ".svg"; File pngDiagramFile = new File(directory, pngFileName); @@ -442,9 +450,9 @@ public static List exportDiagram(Diagram diagram, File directory) throws results.add(directory.getName() + "/" + svgFileName); try { - ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgDiagramFile, false, dpi, scalePercent); + MDUtils.exportSVG(svgDiagramFile,diagramPresentationElement); ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, pngDiagramFile, false, dpi, scalePercent); - } catch (IOException e) { + } catch (IOException | TransformerException e) { e.printStackTrace(); return results; } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java index 17ab179af..f8c7c1c3e 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java @@ -12,8 +12,8 @@ import com.nomagic.uml2.ext.jmi.helpers.ModelHelper; import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper; import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdmodels.Model; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector; import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype; import com.nomagic.uml2.ext.magicdraw.metadata.UMLPackage; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java index 64845c452..228d3d82a 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java @@ -51,6 +51,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -268,7 +272,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { viewResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { failure = true; Application.getInstance().getGUILog().log("[ERROR] An error occurred. View generation aborted. Please check your network connection or view logs for more information. Reason: " + e.getMessage()); e.printStackTrace(); @@ -336,7 +340,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { instanceAndSlotResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { failure = true; Application.getInstance().getGUILog().log("[ERROR] An error occurred. View generation aborted. Please check your network connection or view logs for more information. Reason: " + e.getMessage()); e.printStackTrace(); @@ -660,7 +664,7 @@ public List getEStructuralFeatureOverrides() { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -692,7 +696,7 @@ public List getEStructuralFeatureOverrides() { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index d5be33fbf..5aca2dbe9 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -35,17 +35,24 @@ import org.apache.http.client.entity.EntityBuilder; import org.apache.http.client.methods.*; import org.apache.http.client.utils.URIBuilder; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.entity.ContentType; import org.apache.http.entity.FileEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import javax.net.ssl.SSLContext; import javax.swing.*; import java.io.*; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; +import java.security.*; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -74,7 +81,8 @@ public static AtomicReference getLastException() { return LAST_EXCEPTION; } - public static ObjectNode getElement(Project project, String elementId, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static ObjectNode getElement(Project project, String elementId, ProgressStatus progressStatus) + throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { Collection elementIds = new ArrayList<>(1); elementIds.add(elementId); File responseFile = getElementsRecursively(project, elementIds, 0, progressStatus); @@ -89,7 +97,8 @@ public static ObjectNode getElement(Project project, String elementId, ProgressS return null; } - public static File getElementRecursively(Project project, String elementId, int depth, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static File getElementRecursively(Project project, String elementId, int depth, ProgressStatus progressStatus) + throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { Collection elementIds = new ArrayList<>(1); elementIds.add(elementId); return getElementsRecursively(project, elementIds, depth, progressStatus); @@ -104,7 +113,8 @@ public static File getElementRecursively(Project project, String elementId, int * @throws IOException * @throws URISyntaxException */ - public static File getElements(Project project, Collection elementIds, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static File getElements(Project project, Collection elementIds, ProgressStatus progressStatus) + throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return getElementsRecursively(project, elementIds, 0, progressStatus); } @@ -118,7 +128,8 @@ public static File getElements(Project project, Collection elementIds, P * @throws IOException * @throws URISyntaxException */ - public static File getElementsRecursively(Project project, Collection elementIds, int depth, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static File getElementsRecursively(Project project, Collection elementIds, int depth, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { // verify elements if (elementIds == null || elementIds.isEmpty()) { return null; @@ -138,7 +149,7 @@ public static File getElementsRecursively(Project project, Collection el return sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.PUT, requestUri, sendData, ContentType.APPLICATION_JSON), progressStatus); } - public static File getArtifacts(Project project, Collection artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static File getArtifacts(Project project, Collection artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (artifactIds == null || artifactIds.isEmpty()) { return null; } @@ -150,15 +161,18 @@ public static File getArtifacts(Project project, Collection artifactIds, return sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.PUT, requestUri, sendData, ContentType.APPLICATION_JSON), progressStatus); } - public static String getCredentialsTicket(Project project, String username, String password, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static String getCredentialsTicket(Project project, String username, String password, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return getCredentialsTicket(project, null, username, password, progressStatus); } - public static String getCredentialsTicket(String baseUrl, String username, String password, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static String getCredentialsTicket(String baseUrl, String username, String password, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return getCredentialsTicket(null, baseUrl, username, password, progressStatus); } - private static String getCredentialsTicket(Project project, String baseUrl, String username, String password, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + private static String getCredentialsTicket(Project project, String baseUrl, String username, String password, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { URIBuilder requestUri = MMSUtils.getServiceUri(project, baseUrl); if (requestUri == null) { return null; @@ -189,7 +203,8 @@ private static String getCredentialsTicket(Project project, String baseUrl, Stri return null; } - public static String validateCredentialsTicket(Project project, String ticket, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static String validateCredentialsTicket(Project project, String ticket, ProgressStatus progressStatus) + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { URIBuilder requestUri = MMSUtils.getServiceUri(project); if (requestUri == null) { return ""; @@ -362,7 +377,7 @@ else if (node instanceof String && jsonBlobType == JsonBlobType.ELEMENT_ID || js * @throws IOException * @throws ServerException */ - public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus, final ObjectNode responseJson) throws IOException, ServerException, URISyntaxException { + public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus, final ObjectNode responseJson) throws IOException, ServerException, URISyntaxException, KeyStoreException, CertificateException, NoSuchAlgorithmException, KeyManagementException { final File responseFile = (responseJson == null ? File.createTempFile("Response-", null) : null); final AtomicReference responseBody = new AtomicReference<>(); final AtomicReference responseCode = new AtomicReference<>(); @@ -372,11 +387,28 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog if (MDUtils.isDeveloperMode()) { Application.getInstance().getGUILog().log(requestSummary); } + KeyStore trustStore = KeyStore.getInstance("JKS"); + + FileInputStream fis = new FileInputStream("./certs/cacerts.jks"); + + trustStore.load(fis,"changeit".toCharArray()); + + fis.close(); + + SSLContext sslContext = SSLContexts.custom() + .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) // use null as second param if you don't have a separate key password + .build(); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + sslContext,new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}, null, + new DefaultHostnameVerifier()); + // create client, execute request, parse response, store in thread safe buffer to return as string later // client, response, and reader are all auto closed after block if (progressStatus == null) { - try (CloseableHttpClient httpclient = HttpClients.createDefault(); + try (CloseableHttpClient httpclient = HttpClients.custom() + .setSSLSocketFactory(sslsf) + .build(); CloseableHttpResponse response = httpclient.execute(request); InputStream inputStream = response.getEntity().getContent()) { responseCode.set(response.getStatusLine().getStatusCode()); @@ -394,7 +426,9 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog LAST_EXCEPTION.set(null); progressStatus.setIndeterminate(true); Future future = TaskRunner.runWithProgressStatus(() -> { - try (CloseableHttpClient httpclient = HttpClients.createDefault(); + try (CloseableHttpClient httpclient = HttpClients.custom() + .setSSLSocketFactory(sslsf) + .build(); CloseableHttpResponse response = httpclient.execute(request); InputStream inputStream = response.getEntity().getContent()) { responseCode.set(response.getStatusLine().getStatusCode()); @@ -454,11 +488,11 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog return responseFile; } - public static File sendMMSRequest(Project project, HttpRequestBase request) throws IOException, ServerException, URISyntaxException { + public static File sendMMSRequest(Project project, HttpRequestBase request) throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return sendMMSRequest(project, request, null, null); } - public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException { + public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { return sendMMSRequest(project, request, progressStatus, null); } @@ -561,7 +595,8 @@ else if (ProjectUtilities.isStandardSystemProfile(project.getPrimaryProject())) return urlString.trim(); } - public static String getMmsOrg(Project project) throws IOException, URISyntaxException, ServerException { + public static String getMmsOrg(Project project) + throws IOException, URISyntaxException, ServerException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { URIBuilder uriBuilder = getServiceProjectsUri(project); File responseFile = sendMMSRequest(project, buildRequest(HttpRequestType.GET, uriBuilder)); try (JsonParser responseParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { @@ -613,7 +648,18 @@ private static URIBuilder getServiceUri(Project project, String baseUrl) { return null; } - uri.setPath("/alfresco/service"); + String currentPath = uri.getPath(); + + // If current path ends in '/', append alfresco/service + if (currentPath.endsWith("/")) { + uri.setPath(uri.getPath() + "alfresco/service"); + } + // Otherwise, append /alfresco/service + else { + uri.setPath(uri.getPath() + "/alfresco/service"); + } + + if (project != null && TicketUtils.isTicketSet(project)) { uri.setParameter("alf_ticket", TicketUtils.getTicket(project)); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java index 1c310419b..befa50e61 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java @@ -37,6 +37,10 @@ import java.io.IOException; import java.lang.reflect.Field; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -179,7 +183,7 @@ public void run(ProgressStatus progressStatus) { } } } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS branches. Branch commit aborted. Reason: " + e.getMessage()); return; @@ -212,7 +216,7 @@ public void run(ProgressStatus progressStatus) { File sendFile = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, refsNodes, MMSUtils.JsonBlobType.REF); HttpRequestBase request = MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, requestUri, sendFile, ContentType.APPLICATION_JSON); MMSUtils.sendMMSRequest(project, request); - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while posting branch. Branch commit aborted. Reason: " + e.getMessage()); e.printStackTrace(); return; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java index 473ff8101..fe55aa0dd 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java @@ -23,6 +23,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; @@ -124,7 +128,7 @@ private static void request(List elementsToUpdate, List elem TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -144,7 +148,7 @@ private static void request(List elementsToUpdate, List elem TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java index 52fe7b7b7..52a4ea54f 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java @@ -29,6 +29,10 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -86,7 +90,7 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) { File file = MMSUtils.createEntityFile(CommitClientElementAction.class, ContentType.APPLICATION_JSON, Collections.singleton(objectNode), MMSUtils.JsonBlobType.ELEMENT_JSON); HttpRequestBase request = MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, elementsRequestUri, file, ContentType.APPLICATION_JSON); MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] Failed to commit diagram artifacts for " + Converters.getElementToHumanNameConverter().apply(diagram) + ". Reason: " + e.getMessage()); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java index 5e05c462b..574ffa6d8 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java @@ -21,6 +21,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.Collection; import java.util.LinkedList; import java.util.UUID; @@ -95,7 +99,7 @@ public String commitAction() { } } } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS orgs. Aborting org creation. Reason: " + e.getMessage()); e.printStackTrace(); return null; @@ -113,7 +117,7 @@ public String commitAction() { try { File sendData = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, orgs, MMSUtils.JsonBlobType.ORG); MMSUtils.sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, requestUri, sendData, ContentType.APPLICATION_JSON)); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while committing org. Org commit cancelled. Reason: " + e.getMessage()); e.printStackTrace(); return null; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java index 11c6228e5..07aa5e774 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java @@ -27,6 +27,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.*; public class CommitProjectAction extends RuleViolationAction implements AnnotationAction, IRuleViolationAction { @@ -78,7 +82,7 @@ public String commitAction() { try { orgId = MMSUtils.getMmsOrg(project); // a null result here just means the project isn't on mms - } catch (IOException | URISyntaxException | ServerException e1) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while checking for project org on MMS. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; @@ -92,7 +96,7 @@ public String commitAction() { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e1) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS orgs. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; @@ -156,7 +160,7 @@ public String toString() { // crude method of waiting for project post to propagate Thread.sleep(5000); } - } catch (IOException | URISyntaxException | ServerException | InterruptedException e1) { + } catch (IOException | URISyntaxException | ServerException | InterruptedException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while posting project to MMS. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java index ae5a5fc61..2135089e1 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java @@ -21,6 +21,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.Collection; import java.util.Map; @@ -79,7 +83,7 @@ public static boolean postImage(Project project, String key, Map { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java index 5bb6b5f5f..2d58e4775 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java @@ -13,6 +13,10 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; public class MMSLoginAction extends MDAction { private static final long serialVersionUID = 1L; @@ -45,7 +49,7 @@ public static boolean loginAction(Project project) { TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSDeltaProjectEventListenerAdapter.getProjectMapping(project).update(); - } catch (URISyntaxException | IOException | ServerException e) { + } catch (URISyntaxException | IOException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); } }, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java index cc3a95647..7b2e7d1ad 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java @@ -36,6 +36,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -72,7 +76,7 @@ public void run(ProgressStatus progressStatus) { Utils.guilog("[WARNING] You are not logged in to MMS. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync."); return; } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { Utils.guilog("[ERROR] An error occurred while validating credentials. Credentials will be cleared. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync. Reason: " + e.getMessage()); return; } @@ -114,7 +118,7 @@ public void run(ProgressStatus progressStatus) { Application.getInstance().getGUILog().log("[WARNING] MMS history is unavailable. Skipping sync. All changes will be re-attempted in the next sync."); return; } - } catch (URISyntaxException | IOException | IllegalStateException | ServerException e) { + } catch (URISyntaxException | IOException | IllegalStateException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException | ServerException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while updating MMS history. Credentials will be cleared. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync. Reason: " + e.getMessage()); e.printStackTrace(); return; @@ -185,7 +189,7 @@ else if (value instanceof Element) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { if (progressStatus.isCancel()) { Application.getInstance().getGUILog().log("[INFO] Sync manually cancelled. All changes will be re-attempted in the next sync."); return; @@ -325,7 +329,7 @@ else if (shouldUpdate && mmsChange != null) { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -351,7 +355,7 @@ else if (shouldUpdate && mmsChange != null) { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java index 609a6025a..d4b8a2fd9 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java @@ -21,6 +21,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.*; import java.util.stream.Collectors; @@ -114,7 +118,7 @@ public void run(ProgressStatus progressStatus) { responseFiles.add(responseFile); } } - } catch (ServerException | URISyntaxException | IOException e) { + } catch (ServerException | URISyntaxException | IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting elements from the server. Manual sync aborted. Reason: " + e.getMessage()); e.printStackTrace(); validationSuite = null; @@ -155,7 +159,7 @@ private static void collectClientElementsRecursively(Project project, Element el } private static File collectServerElementsRecursively(Project project, Element element, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException { + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { String id = Converters.getElementToIdConverter().apply(element); Collection elementIds = new ArrayList<>(1); elementIds.add(id); @@ -163,7 +167,7 @@ private static File collectServerElementsRecursively(Project project, Element el } private static File collectServerModuleElementsRecursively(Project project, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException { + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { Collection attachedModels = new ArrayList<>(project.getModels()); attachedModels.remove(project.getPrimaryModel()); Collection attachedModelIds = attachedModels.stream().map(Converters.getElementToIdConverter()).filter(amId -> amId != null).collect(Collectors.toList()); @@ -171,7 +175,7 @@ private static File collectServerModuleElementsRecursively(Project project, int } private static File collectServerHoldingBinElementsRecursively(Project project, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException { + throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { String holdingBinId = MDKConstants.HOLDING_BIN_ID_PREFIX + Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()); return MMSUtils.getElementRecursively(project, holdingBinId, depth, progressStatus); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java index 7e41ab17c..854ab7b13 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java @@ -30,6 +30,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; import java.util.*; import java.util.concurrent.ScheduledFuture; @@ -48,7 +52,7 @@ public void projectOpened(Project project) { getProjectMapping(project).setScheduledFuture(TaskRunner.scheduleWithProgressStatus(progressStatus -> { try { getProjectMapping(project).update(); - } catch (URISyntaxException | IOException | ServerException e) { + } catch (URISyntaxException | IOException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); } }, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false, (r, ses) -> ses.scheduleAtFixedRate(r, 0, 1, TimeUnit.MINUTES))); @@ -159,7 +163,7 @@ public String getLastSyncedMmsCommit() throws RuntimeException { }).map(json -> json.get("commitId")).filter(commitIdNode -> commitIdNode != null && commitIdNode.isTextual()).map(JsonNode::asText).findAny().orElse(null); } - public synchronized boolean update() throws URISyntaxException, IOException, ServerException, IllegalStateException { + public synchronized boolean update() throws URISyntaxException, IOException, ServerException, IllegalStateException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (!project.isRemote()) { return false; } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java index 315f4a429..f9da757b4 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java @@ -19,6 +19,10 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; /** @@ -184,7 +188,7 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) { MMSDeltaProjectEventListenerAdapter.getProjectMapping(project).update(); progressStatus.setDescription("Updating table"); update(); - } catch (URISyntaxException | IOException | ServerException e) { + } catch (URISyntaxException | IOException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); } }, "Sync Status Update", false, 0); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java index 0a8876477..9d5113599 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java @@ -33,6 +33,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.text.NumberFormat; import java.util.*; @@ -143,7 +147,7 @@ public void validate(ProgressStatus progressStatus, boolean allBranches) { } } } - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { errors = true; e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS branches. Branch validation aborted. Reason: " + e.getMessage()); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java index e5844889b..d9c74dd9c 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java @@ -18,6 +18,7 @@ import gov.nasa.jpl.mbee.mdk.mms.MMSUtils; import gov.nasa.jpl.mbee.mdk.mms.actions.CommitDiagramArtifactsAction; import gov.nasa.jpl.mbee.mdk.mms.actions.ValidateElementAction; +import gov.nasa.jpl.mbee.mdk.util.MDUtils; import gov.nasa.jpl.mbee.mdk.util.Pair; import gov.nasa.jpl.mbee.mdk.validation.ValidationRule; import gov.nasa.jpl.mbee.mdk.validation.ValidationRuleViolation; @@ -26,10 +27,15 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.http.entity.ContentType; +import javax.xml.transform.TransformerException; import java.io.*; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.*; import java.util.stream.Collectors; @@ -79,7 +85,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { diagramElementsResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation. Reason: " + e.getMessage()); return; @@ -118,7 +124,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { artifactsResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation. Reason: " + e.getMessage()); return; @@ -161,13 +167,21 @@ public void run(ProgressStatus progressStatus) { for (Map.Entry> entry : EXPORT_FORMATS.entrySet()) { Path path; String checksum; + + Application.getInstance().getGUILog().log("[INFO] Generating Diagram of type" + diagramPresentationElement.getDiagramType().getRootType() + "."); + try { + path = Files.createTempFile(DiagramValidator.class.getSimpleName() + "-" + diagramId, "." + entry.getKey()); - ImageExporter.export(diagramPresentationElement, entry.getValue().getKey(), path.toFile()); + if (entry.getValue().getKey() == ImageExporter.SVG) { + MDUtils.exportSVG(path.toFile(),diagramPresentationElement); + }else { + ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, path.toFile()); + } try (InputStream inputStream = new FileInputStream(path.toFile())) { checksum = DigestUtils.md5Hex(inputStream); } - } catch (IOException e) { + } catch (IOException | TransformerException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation for " + Converters.getElementToHumanNameConverter().apply(diagram) + ". Reason: " + e.getMessage()); break; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java index ec9c31318..b277eed31 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java @@ -13,6 +13,7 @@ import com.nomagic.task.RunnableWithProgress; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; +import gov.nasa.jpl.mbee.mdk.MDKPlugin; import gov.nasa.jpl.mbee.mdk.actions.ClipboardAction; import gov.nasa.jpl.mbee.mdk.api.incubating.MDKConstants; import gov.nasa.jpl.mbee.mdk.api.incubating.convert.Converters; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java index 70522d6c9..5e2146f09 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java @@ -23,6 +23,10 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; /** * SysML 2 Pilot Implementation @@ -72,7 +76,7 @@ public void validate() { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException e) { + } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { errors = true; e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS projects. Project validation aborted. Reason: " + e.getMessage()); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java index f0cae40bc..f324d97b6 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java @@ -4,6 +4,7 @@ import com.nomagic.magicdraw.core.Project; import com.nomagic.magicdraw.core.ProjectUtilities; import com.nomagic.magicdraw.esi.EsiUtils; +import com.nomagic.magicdraw.export.image.ImageExporter; import com.nomagic.magicdraw.ui.browser.BrowserTabTree; import com.nomagic.magicdraw.ui.browser.Node; import com.nomagic.magicdraw.uml.BaseElement; @@ -12,11 +13,27 @@ import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; import java.awt.event.ActionEvent; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.util.XMLResourceDescriptor; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + /** * A collection of utility functions for accessing the MagicDraw (MD) * application. @@ -181,4 +198,30 @@ public static long getRemoteVersion(Project project) { } return Long.valueOf(ProjectUtilities.getVersion(project.getPrimaryProject()).getName()); } + + public static void exportSVG (File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException { + System.setProperty("svg.enriched.export", Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); + Application.getInstance().getGUILog().log("[INFO] Generating Diagram of type" + diagramPresentationElement.getDiagramType().getRootType() + "."); + int dpi = Application.getInstance().getEnvironmentOptions().getGeneralOptions().getImageResolutionDpi(); + ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, dpi, 100); + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + Document svg = f.createDocument(null, new FileInputStream(svgFile)); + for (org.w3c.dom.Node g: XMLUtil.asList(svg.getElementsByTagName("g"))) { + if (g instanceof org.w3c.dom.Element) { + if (((org.w3c.dom.Element) g).getAttribute("class").equals("element")) { + ((org.w3c.dom.Element) g).setAttribute("stroke-width", "0px"); + } + + } + } + DOMSource source = new DOMSource(svg); + FileWriter writer = new FileWriter(svgFile); + StreamResult result = new StreamResult(writer); + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.transform(source, result); + } + } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java index da58dadb7..3f9a23d58 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java @@ -19,6 +19,10 @@ import java.awt.event.HierarchyListener; import java.io.IOException; import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; @@ -52,7 +56,7 @@ public static boolean isTicketSet(Project project) { return ticket != null && !ticket.isEmpty(); } - public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException { + public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (!isTicketSet(project)) { return false; } @@ -243,7 +247,7 @@ private static boolean acquireTicket(Project project, String pass) { String ticket; try { ticket = MMSUtils.getCredentialsTicket(project, username, pass, progressStatus); - } catch (IOException | URISyntaxException | ServerException e) { + } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while acquiring credentials. Reason: " + e.getMessage()); e.printStackTrace(); return; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java new file mode 100644 index 000000000..9ded36be2 --- /dev/null +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java @@ -0,0 +1,26 @@ +package gov.nasa.jpl.mbee.mdk.util; + +import java.util.*; +import org.w3c.dom.*; + +public final class XMLUtil { + private XMLUtil(){} + + public static List asList(NodeList n) { + return n.getLength()==0? + Collections.emptyList(): new NodeListWrapper(n); + } + static final class NodeListWrapper extends AbstractList + implements RandomAccess { + private final NodeList list; + NodeListWrapper(NodeList l) { + list=l; + } + public Node get(int index) { + return list.item(index); + } + public int size() { + return list.getLength(); + } + } +} \ No newline at end of file diff --git a/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java b/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java index 22a34154b..242215262 100644 --- a/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java +++ b/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java @@ -19,35 +19,18 @@ import org.gradle.api.Action; import org.gradle.api.logging.LogLevel; import org.gradle.internal.UncheckedException; -import org.gradle.internal.concurrent.ExecutorFactory; -import org.gradle.internal.event.DefaultListenerManager; -import org.gradle.internal.event.ListenerManager; import org.gradle.internal.io.ClassLoaderObjectInputStream; +import org.gradle.internal.serialize.Decoder; +import org.gradle.internal.serialize.InputStreamBackedDecoder; import org.gradle.internal.logging.LoggingManagerInternal; import org.gradle.internal.logging.services.LoggingServiceRegistry; import org.gradle.internal.remote.MessagingClient; import org.gradle.internal.remote.ObjectConnection; +import org.gradle.internal.remote.services.MessagingServices; import org.gradle.internal.remote.internal.inet.MultiChoiceAddress; import org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer; -import org.gradle.internal.remote.services.MessagingServices; -import org.gradle.internal.serialize.Decoder; -import org.gradle.internal.serialize.InputStreamBackedDecoder; -import org.gradle.internal.service.DefaultServiceRegistry; -import org.gradle.internal.service.ServiceRegistry; -import org.gradle.process.internal.health.memory.DefaultJvmMemoryInfo; -import org.gradle.process.internal.health.memory.DefaultMemoryManager; -import org.gradle.process.internal.health.memory.DisabledOsMemoryInfo; -import org.gradle.process.internal.health.memory.JvmMemoryInfo; -import org.gradle.process.internal.health.memory.JvmMemoryStatus; -import org.gradle.process.internal.health.memory.JvmMemoryStatusListener; -import org.gradle.process.internal.health.memory.MemoryManager; -import org.gradle.process.internal.health.memory.OsMemoryInfo; -import org.gradle.process.internal.worker.WorkerLoggingSerializer; -import org.gradle.process.internal.worker.WorkerJvmMemoryInfoSerializer; +import org.gradle.process.internal.worker.child.ApplicationClassesInSystemClassLoaderWorkerFactory; import org.gradle.process.internal.worker.child.WorkerContext; -import org.gradle.process.internal.worker.child.WorkerJvmMemoryInfoProtocol; -import org.gradle.process.internal.worker.child.WorkerLogEventListener; -import org.gradle.process.internal.worker.child.WorkerLoggingProtocol; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -82,35 +65,25 @@ public Void call() throws Exception { LoggingManagerInternal loggingManager = createLoggingManager(); loggingManager.setLevelInternal(LogLevel.values()[logLevel]).start(); - // Read whether process info should be published - boolean shouldPublishJvmMemoryInfo = decoder.readBoolean(); - // Read server address and start connecting MultiChoiceAddress serverAddress = new MultiChoiceAddressSerializer().read(decoder); - MessagingServices messagingServices = new MessagingServices(); - MagicDrawClassLoaderWorker.WorkerServices workerServices = new MagicDrawClassLoaderWorker.WorkerServices(messagingServices); + MessagingServices messagingServices = createClient(); - WorkerLogEventListener workerLogEventListener = null; try { - // Read serialized worker - byte[] serializedWorker = decoder.readBinary(); - - // Deserialize the worker action - Action action; - try { - ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader()); - action = (Action) instr.readObject(); - } catch (Exception e) { - throw UncheckedException.throwAsUncheckedException(e); - } - final ObjectConnection connection = messagingServices.get(MessagingClient.class).getConnection(serverAddress); - workerLogEventListener = configureLogging(loggingManager, connection); - if (shouldPublishJvmMemoryInfo) { - configureWorkerJvmMemoryInfoEvents(workerServices, connection); - } try { + // Read serialized worker + byte[] serializedWorker = decoder.readBinary(); + + // Deserialize the worker action + Action action; + try { + ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader()); + action = (Action) instr.readObject(); + } catch (Exception e) { + throw UncheckedException.throwAsUncheckedException(e); + } action.execute(new WorkerContext() { public ClassLoader getApplicationClassLoader() { //return ClassLoader.getSystemClassLoader(); @@ -126,60 +99,17 @@ public ObjectConnection getServerConnection() { connection.stop(); } } finally { - if (workerLogEventListener != null) { - loggingManager.removeOutputEventListener(workerLogEventListener); - } messagingServices.close(); - loggingManager.stop(); } return null; } - private WorkerLogEventListener configureLogging(LoggingManagerInternal loggingManager, ObjectConnection connection) { - connection.useParameterSerializers(WorkerLoggingSerializer.create()); - WorkerLoggingProtocol workerLoggingProtocol = connection.addOutgoing(WorkerLoggingProtocol.class); - WorkerLogEventListener workerLogEventListener = new WorkerLogEventListener(workerLoggingProtocol); - loggingManager.addOutputEventListener(workerLogEventListener); - return workerLogEventListener; - } - - private void configureWorkerJvmMemoryInfoEvents(MagicDrawClassLoaderWorker.WorkerServices services, ObjectConnection connection) { - connection.useParameterSerializers(WorkerJvmMemoryInfoSerializer.create()); - final WorkerJvmMemoryInfoProtocol workerJvmMemoryInfoProtocol = connection.addOutgoing(WorkerJvmMemoryInfoProtocol.class); - services.get(MemoryManager.class).addListener(new JvmMemoryStatusListener() { - @Override - public void onJvmMemoryStatus(JvmMemoryStatus jvmMemoryStatus) { - workerJvmMemoryInfoProtocol.sendJvmMemoryStatus(jvmMemoryStatus); - } - }); + MessagingServices createClient() { + return new MessagingServices(); } LoggingManagerInternal createLoggingManager() { - LoggingManagerInternal loggingManagerInternal = LoggingServiceRegistry.newEmbeddableLogging().newInstance(LoggingManagerInternal.class); - loggingManagerInternal.captureSystemSources(); - return loggingManagerInternal; - } - - private static class WorkerServices extends DefaultServiceRegistry { - public WorkerServices(ServiceRegistry... parents) { - super(parents); - } - - ListenerManager createListenerManager() { - return new DefaultListenerManager(); - } - - OsMemoryInfo createOsMemoryInfo() { - return new DisabledOsMemoryInfo(); - } - - JvmMemoryInfo createJvmMemoryInfo() { - return new DefaultJvmMemoryInfo(); - } - - MemoryManager createMemoryManager(OsMemoryInfo osMemoryInfo, JvmMemoryInfo jvmMemoryInfo, ListenerManager listenerManager, ExecutorFactory executorFactory) { - return new DefaultMemoryManager(osMemoryInfo, jvmMemoryInfo, listenerManager, executorFactory); - } + return LoggingServiceRegistry.newCommandLineProcessLogging().newInstance(LoggingManagerInternal.class); } } From 0e305e49b11615e65162b16b38da429c04031305 Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 19:22:01 -0700 Subject: [PATCH 02/11] Fix Windows path separator related build issue --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0e3bf979d..c3ea9aaa3 100644 --- a/build.gradle +++ b/build.gradle @@ -272,7 +272,7 @@ class PreDist extends DefaultTask { String pluginLibraries = '' project.fileTree(dir: "build/generated-dist/plugins/${groupName}", include: '**/*.jar').each { file -> - pluginLibraries += '\t\t' + System.lineSeparator() + pluginLibraries += '\t\t' + System.lineSeparator() } project.copy { from 'src/main/dist/template/plugins/${group}/plugin.xml' @@ -284,7 +284,7 @@ class PreDist extends DefaultTask { String descriptorFiles = '' project.fileTree(dir: 'build/generated-dist').each { file -> - String relativePath = file.absolutePath.replaceAll(/.*build\/generated-dist\//, '') + String relativePath = file.absolutePath.replace(File.separator, '/').replaceAll(/.*build\/generated-dist\//, '') descriptorFiles += '\t\t' + System.lineSeparator() } project.copy { From 67ebc026e343399eff94f7e698d2c1ed84ba818f Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 20:34:03 -0700 Subject: [PATCH 03/11] Clean up and partially revert for PR #187 --- .../java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java | 4 +- .../mbee/mdk/actions/MMSViewLinkAction.java | 2 +- .../mbee/mdk/cli/AutomatedViewGenerator.java | 7 +- .../nasa/jpl/mbee/mdk/docgen/DocGenUtils.java | 27 ++--- .../generator/ViewPresentationGenerator.java | 15 +-- .../gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java | 59 ++++------ .../mdk/mms/actions/CommitBranchAction.java | 9 +- .../actions/CommitClientElementAction.java | 9 +- .../actions/CommitDiagramArtifactsAction.java | 7 +- .../mbee/mdk/mms/actions/CommitOrgAction.java | 9 +- .../mdk/mms/actions/CommitProjectAction.java | 11 +- .../jpl/mbee/mdk/mms/actions/ExportImage.java | 7 +- .../mbee/mdk/mms/actions/MMSLoginAction.java | 7 +- .../mdk/mms/sync/delta/DeltaSyncRunner.java | 15 +-- .../mdk/mms/sync/manual/ManualSyncRunner.java | 13 +-- .../MMSDeltaProjectEventListenerAdapter.java | 9 +- .../sync/status/actions/SyncStatusAction.java | 7 +- .../mdk/mms/validation/BranchValidator.java | 7 +- .../mdk/mms/validation/DiagramValidator.java | 20 ++-- .../mdk/mms/validation/ElementValidator.java | 1 - .../mdk/mms/validation/ProjectValidator.java | 13 +-- .../gov/nasa/jpl/mbee/mdk/util/MDUtils.java | 64 +++++------ .../nasa/jpl/mbee/mdk/util/TicketUtils.java | 9 +- .../gov/nasa/jpl/mbee/mdk/util/XMLUtil.java | 23 ++-- .../framework/MagicDrawClassLoaderWorker.java | 108 +++++++++++++++--- 25 files changed, 232 insertions(+), 230 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java b/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java index fd1426155..6262d3e52 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/MDKPlugin.java @@ -13,10 +13,11 @@ import com.nomagic.magicdraw.plugins.PluginUtils; import com.nomagic.magicdraw.uml.DiagramDescriptor; import com.nomagic.magicdraw.uml.DiagramTypeConstants; +import gov.nasa.jpl.mbee.mdk.cli.AutomatedCommitter; +import gov.nasa.jpl.mbee.mdk.cli.AutomatedViewGenerator; import gov.nasa.jpl.mbee.mdk.mms.sync.status.SyncStatusConfigurator; import gov.nasa.jpl.mbee.mdk.options.MDKOptionsGroup; import gov.nasa.jpl.mbee.mdk.util.MDUtils; -import gov.nasa.jpl.mbee.mdk.cli.AutomatedViewGenerator; import java.io.File; import java.lang.reflect.Method; @@ -81,6 +82,7 @@ public void init() { EvaluationConfigurator.getInstance().registerBinaryImplementers(this.getClass().getClassLoader()); CommandLineActionManager.getInstance().addAction(new AutomatedViewGenerator()); + CommandLineActionManager.getInstance().addAction(new AutomatedCommitter()); MDKConfigurator mdkConfigurator = new MDKConfigurator(); acm.addMainMenuConfigurator(mdkConfigurator); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java index a459dd30b..cc049b88b 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/actions/MMSViewLinkAction.java @@ -58,7 +58,7 @@ public void actionPerformed(ActionEvent e) { //projects/PROJECT-ID_5_17_16_1_31_54_PM_5fc737b6_154bba92ecd_4cc1_cae_tw_jpl_nasa_gov_127_0_0_1/master/documents/_18_5_83a025f_1491339810716_846504_4332/views/_18_5_83a025f_1491339810716_846504_4332 // include this in the host portion of the uri. not technically correct, but it prevents the # from being converted and breaking things - uriBase.setHost(uriBase.getHost() + "/#"); + uriBase.setHost(uriBase.getHost() + "/alfresco/mmsapp/mms.html#"); uriBase.setPath(""); String uriPath; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java index 92b809728..9db2d0daf 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/cli/AutomatedViewGenerator.java @@ -32,10 +32,7 @@ import java.io.*; import java.net.HttpURLConnection; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -269,7 +266,7 @@ private void loadTeamworkProject() throws IOException, URISyntaxException, Inter mmsRefUri.setParameter("alf_ticket", ticketStore).setPath(mmsRefUri.getPath() + "/" + parser.getOptionValue(REF_ID)); MMSUtils.sendMMSRequest(null, MMSUtils.buildRequest(MMSUtils.HttpRequestType.GET, mmsRefUri), null, refsNode); } - } catch (IOException | ServerException | KeyStoreException | CertificateException | NoSuchAlgorithmException | KeyManagementException e) { + } catch (IOException | ServerException | GeneralSecurityException e) { illegalStateFailure("[FAILURE] Unable to load project, exception occurred while resolving one of the required project URI parameters."); e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java index e782cafe5..1be8b4206 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java @@ -1,7 +1,6 @@ package gov.nasa.jpl.mbee.mdk.docgen; import com.nomagic.magicdraw.core.Application; -import com.nomagic.magicdraw.core.GUILog; import com.nomagic.magicdraw.core.Project; import com.nomagic.magicdraw.export.image.ImageExporter; import com.nomagic.magicdraw.properties.BooleanProperty; @@ -19,7 +18,10 @@ import org.jsoup.select.Elements; import javax.xml.transform.TransformerException; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -89,6 +91,9 @@ public class DocGenUtils { }; private static final Pattern ENTITY_PATTERN = Pattern.compile("(&[^\\s]+?;)"); + public static int DOCGEN_DIAGRAM_DPI = 72; + public static int DOCGEN_DIAGRAM_SCALE_PERCENT = 100; + /** * docbook ignores regular white space in table cells, this is to force * indentation in docbook, 1 indent is 4 spaces @@ -420,13 +425,11 @@ public static String html2docbook(String html) { * will be the diagram id in magicdraw. The images will be 72 dpi and 100% * scaling. * - * @param diagram the magicdraw diagram element - * @param directory directory for docbook xml output (without trailing slash) + * @param diagram the magicdraw diagram element + * @param directory directory for docbook xml output (without trailing slash) * @throws IOException */ public static List exportDiagram(Diagram diagram, File directory) throws IOException { - int dpi = Application.getInstance().getEnvironmentOptions().getGeneralOptions().getImageResolutionDpi(); - int scalePercent = 100; Project project = Application.getInstance().getProject(); if (project == null) { return Collections.emptyList(); @@ -437,12 +440,6 @@ public static List exportDiagram(Diagram diagram, File directory) throws return Collections.emptyList(); } - System.setProperty("svg.enriched.export", Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); - - Application.getInstance().getGUILog().log("[INFO] Generating Diagram of type" + diagramPresentationElement.getDiagramType().getRootType() + "."); - - - String pngFileName = diagramPresentationElement.getID() + ".png"; String svgFileName = diagramPresentationElement.getID() + ".svg"; File pngDiagramFile = new File(directory, pngFileName); @@ -450,9 +447,9 @@ public static List exportDiagram(Diagram diagram, File directory) throws results.add(directory.getName() + "/" + svgFileName); try { - MDUtils.exportSVG(svgDiagramFile,diagramPresentationElement); - ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, pngDiagramFile, false, dpi, scalePercent); - } catch (IOException | TransformerException e) { + MDUtils.exportSVG(svgDiagramFile, diagramPresentationElement); + ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, pngDiagramFile, false, DOCGEN_DIAGRAM_DPI, DOCGEN_DIAGRAM_SCALE_PERCENT); + } catch (IOException e) { e.printStackTrace(); return results; } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java index 228d3d82a..a0dc89507 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/generator/ViewPresentationGenerator.java @@ -16,8 +16,8 @@ import com.nomagic.task.EmptyProgressStatus; import com.nomagic.task.ProgressStatus; import com.nomagic.task.RunnableWithProgress; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.*; import gov.nasa.jpl.mbee.mdk.api.incubating.MDKConstants; import gov.nasa.jpl.mbee.mdk.api.incubating.convert.Converters; import gov.nasa.jpl.mbee.mdk.docgen.ViewViewpointValidator; @@ -51,10 +51,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -272,7 +269,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { viewResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { failure = true; Application.getInstance().getGUILog().log("[ERROR] An error occurred. View generation aborted. Please check your network connection or view logs for more information. Reason: " + e.getMessage()); e.printStackTrace(); @@ -340,7 +337,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { instanceAndSlotResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { failure = true; Application.getInstance().getGUILog().log("[ERROR] An error occurred. View generation aborted. Please check your network connection or view logs for more information. Reason: " + e.getMessage()); e.printStackTrace(); @@ -664,7 +661,7 @@ public List getEStructuralFeatureOverrides() { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -696,7 +693,7 @@ public List getEStructuralFeatureOverrides() { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index 5aca2dbe9..0a8644e52 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -51,8 +51,8 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; -import java.security.*; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; +import java.security.KeyStore; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -82,7 +82,7 @@ public static AtomicReference getLastException() { } public static ObjectNode getElement(Project project, String elementId, ProgressStatus progressStatus) - throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws IOException, ServerException, URISyntaxException, GeneralSecurityException { Collection elementIds = new ArrayList<>(1); elementIds.add(elementId); File responseFile = getElementsRecursively(project, elementIds, 0, progressStatus); @@ -98,7 +98,7 @@ public static ObjectNode getElement(Project project, String elementId, ProgressS } public static File getElementRecursively(Project project, String elementId, int depth, ProgressStatus progressStatus) - throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws IOException, ServerException, URISyntaxException, GeneralSecurityException { Collection elementIds = new ArrayList<>(1); elementIds.add(elementId); return getElementsRecursively(project, elementIds, depth, progressStatus); @@ -114,7 +114,7 @@ public static File getElementRecursively(Project project, String elementId, int * @throws URISyntaxException */ public static File getElements(Project project, Collection elementIds, ProgressStatus progressStatus) - throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws IOException, ServerException, URISyntaxException, GeneralSecurityException { return getElementsRecursively(project, elementIds, 0, progressStatus); } @@ -129,7 +129,7 @@ public static File getElements(Project project, Collection elementIds, P * @throws URISyntaxException */ public static File getElementsRecursively(Project project, Collection elementIds, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { // verify elements if (elementIds == null || elementIds.isEmpty()) { return null; @@ -149,7 +149,7 @@ public static File getElementsRecursively(Project project, Collection el return sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.PUT, requestUri, sendData, ContentType.APPLICATION_JSON), progressStatus); } - public static File getArtifacts(Project project, Collection artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + public static File getArtifacts(Project project, Collection artifactIds, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, GeneralSecurityException { if (artifactIds == null || artifactIds.isEmpty()) { return null; } @@ -162,17 +162,17 @@ public static File getArtifacts(Project project, Collection artifactIds, } public static String getCredentialsTicket(Project project, String username, String password, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { return getCredentialsTicket(project, null, username, password, progressStatus); } public static String getCredentialsTicket(String baseUrl, String username, String password, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { return getCredentialsTicket(null, baseUrl, username, password, progressStatus); } private static String getCredentialsTicket(Project project, String baseUrl, String username, String password, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { URIBuilder requestUri = MMSUtils.getServiceUri(project, baseUrl); if (requestUri == null) { return null; @@ -204,7 +204,7 @@ private static String getCredentialsTicket(Project project, String baseUrl, Stri } public static String validateCredentialsTicket(Project project, String ticket, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { URIBuilder requestUri = MMSUtils.getServiceUri(project); if (requestUri == null) { return ""; @@ -377,7 +377,7 @@ else if (node instanceof String && jsonBlobType == JsonBlobType.ELEMENT_ID || js * @throws IOException * @throws ServerException */ - public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus, final ObjectNode responseJson) throws IOException, ServerException, URISyntaxException, KeyStoreException, CertificateException, NoSuchAlgorithmException, KeyManagementException { + public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus, final ObjectNode responseJson) throws IOException, ServerException, GeneralSecurityException { final File responseFile = (responseJson == null ? File.createTempFile("Response-", null) : null); final AtomicReference responseBody = new AtomicReference<>(); final AtomicReference responseCode = new AtomicReference<>(); @@ -387,21 +387,18 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog if (MDUtils.isDeveloperMode()) { Application.getInstance().getGUILog().log(requestSummary); } - KeyStore trustStore = KeyStore.getInstance("JKS"); - - FileInputStream fis = new FileInputStream("./certs/cacerts.jks"); - - trustStore.load(fis,"changeit".toCharArray()); + KeyStore trustStore = KeyStore.getInstance("JKS"); + FileInputStream fis = new FileInputStream("./certs/cacerts.jks"); + trustStore.load(fis, "changeit".toCharArray()); fis.close(); - SSLContext sslContext = SSLContexts.custom() .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) // use null as second param if you don't have a separate key password .build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - sslContext,new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}, null, - new DefaultHostnameVerifier()); - + sslContext, new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}, null, + new DefaultHostnameVerifier() + ); // create client, execute request, parse response, store in thread safe buffer to return as string later // client, response, and reader are all auto closed after block @@ -488,11 +485,11 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog return responseFile; } - public static File sendMMSRequest(Project project, HttpRequestBase request) throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + public static File sendMMSRequest(Project project, HttpRequestBase request) throws IOException, ServerException, URISyntaxException, GeneralSecurityException { return sendMMSRequest(project, request, null, null); } - public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + public static File sendMMSRequest(Project project, HttpRequestBase request, ProgressStatus progressStatus) throws IOException, ServerException, URISyntaxException, GeneralSecurityException { return sendMMSRequest(project, request, progressStatus, null); } @@ -596,7 +593,7 @@ else if (ProjectUtilities.isStandardSystemProfile(project.getPrimaryProject())) } public static String getMmsOrg(Project project) - throws IOException, URISyntaxException, ServerException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws IOException, URISyntaxException, ServerException, GeneralSecurityException { URIBuilder uriBuilder = getServiceProjectsUri(project); File responseFile = sendMMSRequest(project, buildRequest(HttpRequestType.GET, uriBuilder)); try (JsonParser responseParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { @@ -647,19 +644,7 @@ private static URIBuilder getServiceUri(Project project, String baseUrl) { e.printStackTrace(); return null; } - - String currentPath = uri.getPath(); - - // If current path ends in '/', append alfresco/service - if (currentPath.endsWith("/")) { - uri.setPath(uri.getPath() + "alfresco/service"); - } - // Otherwise, append /alfresco/service - else { - uri.setPath(uri.getPath() + "/alfresco/service"); - } - - + uri.setPath((uri.getPath().endsWith("/") ? "" : "/") + "alfresco/service"); if (project != null && TicketUtils.isTicketSet(project)) { uri.setParameter("alf_ticket", TicketUtils.getTicket(project)); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java index befa50e61..87aa8937f 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitBranchAction.java @@ -37,10 +37,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -183,7 +180,7 @@ public void run(ProgressStatus progressStatus) { } } } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS branches. Branch commit aborted. Reason: " + e.getMessage()); return; @@ -216,7 +213,7 @@ public void run(ProgressStatus progressStatus) { File sendFile = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, refsNodes, MMSUtils.JsonBlobType.REF); HttpRequestBase request = MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, requestUri, sendFile, ContentType.APPLICATION_JSON); MMSUtils.sendMMSRequest(project, request); - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while posting branch. Branch commit aborted. Reason: " + e.getMessage()); e.printStackTrace(); return; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java index fe55aa0dd..19d09d7f7 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitClientElementAction.java @@ -23,10 +23,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; @@ -128,7 +125,7 @@ private static void request(List elementsToUpdate, List elem TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -148,7 +145,7 @@ private static void request(List elementsToUpdate, List elem TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java index 52a4ea54f..76f359156 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitDiagramArtifactsAction.java @@ -29,10 +29,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -90,7 +87,7 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) { File file = MMSUtils.createEntityFile(CommitClientElementAction.class, ContentType.APPLICATION_JSON, Collections.singleton(objectNode), MMSUtils.JsonBlobType.ELEMENT_JSON); HttpRequestBase request = MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, elementsRequestUri, file, ContentType.APPLICATION_JSON); MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] Failed to commit diagram artifacts for " + Converters.getElementToHumanNameConverter().apply(diagram) + ". Reason: " + e.getMessage()); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java index 574ffa6d8..327df631d 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitOrgAction.java @@ -21,10 +21,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.LinkedList; import java.util.UUID; @@ -99,7 +96,7 @@ public String commitAction() { } } } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS orgs. Aborting org creation. Reason: " + e.getMessage()); e.printStackTrace(); return null; @@ -117,7 +114,7 @@ public String commitAction() { try { File sendData = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, orgs, MMSUtils.JsonBlobType.ORG); MMSUtils.sendMMSRequest(project, MMSUtils.buildRequest(MMSUtils.HttpRequestType.POST, requestUri, sendData, ContentType.APPLICATION_JSON)); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while committing org. Org commit cancelled. Reason: " + e.getMessage()); e.printStackTrace(); return null; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java index 07aa5e774..912103532 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/CommitProjectAction.java @@ -27,10 +27,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.*; public class CommitProjectAction extends RuleViolationAction implements AnnotationAction, IRuleViolationAction { @@ -82,7 +79,7 @@ public String commitAction() { try { orgId = MMSUtils.getMmsOrg(project); // a null result here just means the project isn't on mms - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while checking for project org on MMS. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; @@ -96,7 +93,7 @@ public String commitAction() { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS orgs. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; @@ -160,7 +157,7 @@ public String toString() { // crude method of waiting for project post to propagate Thread.sleep(5000); } - } catch (IOException | URISyntaxException | ServerException | InterruptedException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e1) { + } catch (IOException | URISyntaxException | ServerException | InterruptedException | GeneralSecurityException e1) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while posting project to MMS. Project commit cancelled. Reason: " + e1.getMessage()); e1.printStackTrace(); return null; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java index 2135089e1..37b97bd9c 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/ExportImage.java @@ -21,10 +21,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.Map; @@ -83,7 +80,7 @@ public static boolean postImage(Project project, String key, Map { try { MMSUtils.sendMMSRequest(project, request, progressStatus); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java index 2d58e4775..5bc8bf127 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/actions/MMSLoginAction.java @@ -13,10 +13,7 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; public class MMSLoginAction extends MDAction { private static final long serialVersionUID = 1L; @@ -49,7 +46,7 @@ public static boolean loginAction(Project project) { TaskRunner.runWithProgressStatus(progressStatus -> { try { MMSDeltaProjectEventListenerAdapter.getProjectMapping(project).update(); - } catch (URISyntaxException | IOException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) { e.printStackTrace(); } }, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java index 7b2e7d1ad..1fad20adf 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/delta/DeltaSyncRunner.java @@ -36,10 +36,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -76,7 +73,7 @@ public void run(ProgressStatus progressStatus) { Utils.guilog("[WARNING] You are not logged in to MMS. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync."); return; } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Utils.guilog("[ERROR] An error occurred while validating credentials. Credentials will be cleared. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync. Reason: " + e.getMessage()); return; } @@ -118,7 +115,7 @@ public void run(ProgressStatus progressStatus) { Application.getInstance().getGUILog().log("[WARNING] MMS history is unavailable. Skipping sync. All changes will be re-attempted in the next sync."); return; } - } catch (URISyntaxException | IOException | IllegalStateException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException | ServerException e) { + } catch (URISyntaxException | IOException | IllegalStateException | GeneralSecurityException | ServerException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while updating MMS history. Credentials will be cleared. Skipping sync. All changes will be persisted in the model and re-attempted in the next sync. Reason: " + e.getMessage()); e.printStackTrace(); return; @@ -189,7 +186,7 @@ else if (value instanceof Element) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { if (progressStatus.isCancel()) { Application.getInstance().getGUILog().log("[INFO] Sync manually cancelled. All changes will be re-attempted in the next sync."); return; @@ -329,7 +326,7 @@ else if (shouldUpdate && mmsChange != null) { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } @@ -355,7 +352,7 @@ else if (shouldUpdate && mmsChange != null) { TaskRunner.runWithProgressStatus(progressStatus1 -> { try { MMSUtils.sendMMSRequest(project, request, progressStatus1); - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { // TODO Implement error handling that was previously not possible due to OutputQueue implementation e.printStackTrace(); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java index d4b8a2fd9..2956bc492 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/manual/ManualSyncRunner.java @@ -21,10 +21,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.*; import java.util.stream.Collectors; @@ -118,7 +115,7 @@ public void run(ProgressStatus progressStatus) { responseFiles.add(responseFile); } } - } catch (ServerException | URISyntaxException | IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (ServerException | URISyntaxException | IOException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting elements from the server. Manual sync aborted. Reason: " + e.getMessage()); e.printStackTrace(); validationSuite = null; @@ -159,7 +156,7 @@ private static void collectClientElementsRecursively(Project project, Element el } private static File collectServerElementsRecursively(Project project, Element element, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { String id = Converters.getElementToIdConverter().apply(element); Collection elementIds = new ArrayList<>(1); elementIds.add(id); @@ -167,7 +164,7 @@ private static File collectServerElementsRecursively(Project project, Element el } private static File collectServerModuleElementsRecursively(Project project, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { Collection attachedModels = new ArrayList<>(project.getModels()); attachedModels.remove(project.getPrimaryModel()); Collection attachedModelIds = attachedModels.stream().map(Converters.getElementToIdConverter()).filter(amId -> amId != null).collect(Collectors.toList()); @@ -175,7 +172,7 @@ private static File collectServerModuleElementsRecursively(Project project, int } private static File collectServerHoldingBinElementsRecursively(Project project, int depth, ProgressStatus progressStatus) - throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + throws ServerException, IOException, URISyntaxException, GeneralSecurityException { String holdingBinId = MDKConstants.HOLDING_BIN_ID_PREFIX + Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()); return MMSUtils.getElementRecursively(project, holdingBinId, depth, progressStatus); } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java index 854ab7b13..2d4688d2d 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/mms/MMSDeltaProjectEventListenerAdapter.java @@ -30,10 +30,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; import java.util.concurrent.ScheduledFuture; @@ -52,7 +49,7 @@ public void projectOpened(Project project) { getProjectMapping(project).setScheduledFuture(TaskRunner.scheduleWithProgressStatus(progressStatus -> { try { getProjectMapping(project).update(); - } catch (URISyntaxException | IOException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) { e.printStackTrace(); } }, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false, (r, ses) -> ses.scheduleAtFixedRate(r, 0, 1, TimeUnit.MINUTES))); @@ -163,7 +160,7 @@ public String getLastSyncedMmsCommit() throws RuntimeException { }).map(json -> json.get("commitId")).filter(commitIdNode -> commitIdNode != null && commitIdNode.isTextual()).map(JsonNode::asText).findAny().orElse(null); } - public synchronized boolean update() throws URISyntaxException, IOException, ServerException, IllegalStateException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + public synchronized boolean update() throws URISyntaxException, IOException, ServerException, IllegalStateException, GeneralSecurityException { if (!project.isRemote()) { return false; } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java index f9da757b4..cc5c0b292 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/sync/status/actions/SyncStatusAction.java @@ -19,10 +19,7 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; /** @@ -188,7 +185,7 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) { MMSDeltaProjectEventListenerAdapter.getProjectMapping(project).update(); progressStatus.setDescription("Updating table"); update(); - } catch (URISyntaxException | IOException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) { e.printStackTrace(); } }, "Sync Status Update", false, 0); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java index 9d5113599..95954a3a3 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/BranchValidator.java @@ -33,10 +33,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.text.NumberFormat; import java.util.*; @@ -147,7 +144,7 @@ public void validate(ProgressStatus progressStatus, boolean allBranches) { } } } - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { errors = true; e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS branches. Branch validation aborted. Reason: " + e.getMessage()); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java index d9c74dd9c..e75b29296 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/DiagramValidator.java @@ -12,6 +12,7 @@ import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Diagram; import gov.nasa.jpl.mbee.mdk.api.incubating.MDKConstants; import gov.nasa.jpl.mbee.mdk.api.incubating.convert.Converters; +import gov.nasa.jpl.mbee.mdk.docgen.DocGenUtils; import gov.nasa.jpl.mbee.mdk.http.ServerException; import gov.nasa.jpl.mbee.mdk.json.JacksonUtils; import gov.nasa.jpl.mbee.mdk.mms.MMSArtifact; @@ -32,10 +33,7 @@ import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.*; import java.util.stream.Collectors; @@ -85,7 +83,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { diagramElementsResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation. Reason: " + e.getMessage()); return; @@ -124,7 +122,7 @@ public void run(ProgressStatus progressStatus) { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { artifactsResponse = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An unexpected error occurred while generating diagrams. Skipping image validation. Reason: " + e.getMessage()); return; @@ -168,15 +166,13 @@ public void run(ProgressStatus progressStatus) { Path path; String checksum; - Application.getInstance().getGUILog().log("[INFO] Generating Diagram of type" + diagramPresentationElement.getDiagramType().getRootType() + "."); - try { - path = Files.createTempFile(DiagramValidator.class.getSimpleName() + "-" + diagramId, "." + entry.getKey()); if (entry.getValue().getKey() == ImageExporter.SVG) { - MDUtils.exportSVG(path.toFile(),diagramPresentationElement); - }else { - ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, path.toFile()); + MDUtils.exportSVG(path.toFile(), diagramPresentationElement); + } + else { + ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, path.toFile(), false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); } try (InputStream inputStream = new FileInputStream(path.toFile())) { checksum = DigestUtils.md5Hex(inputStream); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java index b277eed31..ec9c31318 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ElementValidator.java @@ -13,7 +13,6 @@ import com.nomagic.task.RunnableWithProgress; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import gov.nasa.jpl.mbee.mdk.MDKPlugin; import gov.nasa.jpl.mbee.mdk.actions.ClipboardAction; import gov.nasa.jpl.mbee.mdk.api.incubating.MDKConstants; import gov.nasa.jpl.mbee.mdk.api.incubating.convert.Converters; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java index 5e2146f09..5eea1ef1f 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/validation/ProjectValidator.java @@ -23,25 +23,22 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; /** * SysML 2 Pilot Implementation * Copyright (C) 2018 California Institute of Technology ("Caltech") - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . * @@ -76,7 +73,7 @@ public void validate() { try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } - } catch (IOException | ServerException | URISyntaxException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | ServerException | URISyntaxException | GeneralSecurityException e) { errors = true; e.printStackTrace(); Application.getInstance().getGUILog().log("[ERROR] An error occurred while getting MMS projects. Project validation aborted. Reason: " + e.getMessage()); diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java index f324d97b6..97a0ec553 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java @@ -11,28 +11,22 @@ import com.nomagic.magicdraw.uml.symbols.DiagramPresentationElement; import com.nomagic.magicdraw.uml.symbols.PresentationElement; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; - -import java.awt.event.ActionEvent; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - +import gov.nasa.jpl.mbee.mdk.docgen.DocGenUtils; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; import org.apache.batik.util.XMLResourceDescriptor; import org.w3c.dom.Document; -import org.w3c.dom.NodeList; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; /** * A collection of utility functions for accessing the MagicDraw (MD) @@ -199,29 +193,31 @@ public static long getRemoteVersion(Project project) { return Long.valueOf(ProjectUtilities.getVersion(project.getPrimaryProject()).getName()); } - public static void exportSVG (File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException { - System.setProperty("svg.enriched.export", Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); - Application.getInstance().getGUILog().log("[INFO] Generating Diagram of type" + diagramPresentationElement.getDiagramType().getRootType() + "."); - int dpi = Application.getInstance().getEnvironmentOptions().getGeneralOptions().getImageResolutionDpi(); - ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, dpi, 100); - String parser = XMLResourceDescriptor.getXMLParserClassName(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - Document svg = f.createDocument(null, new FileInputStream(svgFile)); - for (org.w3c.dom.Node g: XMLUtil.asList(svg.getElementsByTagName("g"))) { - if (g instanceof org.w3c.dom.Element) { - if (((org.w3c.dom.Element) g).getAttribute("class").equals("element")) { - ((org.w3c.dom.Element) g).setAttribute("stroke-width", "0px"); - } + public static void exportSVG(File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException { + String SVG_ENRICHED_EXPORT_PROPERTY_NAME = "svg.enriched.export"; + String originalSvgEnrichedExportPropertyValue = System.getProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME); + System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); - } + try { + ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + Document svg = f.createDocument(null, new FileInputStream(svgFile)); + XMLUtil.asList(svg.getElementsByTagName("g")).stream() + .filter(g -> g instanceof org.w3c.dom.Element) + .map(g -> (org.w3c.dom.Element) g) + .filter(g -> Objects.equals(g.getAttribute("class"), "element")) + .forEach(g -> g.setAttribute("stroke-width", "0px")); + DOMSource source = new DOMSource(svg); + FileWriter writer = new FileWriter(svgFile); + StreamResult result = new StreamResult(writer); + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.transform(source, result); + } finally { + System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, originalSvgEnrichedExportPropertyValue); } - DOMSource source = new DOMSource(svg); - FileWriter writer = new FileWriter(svgFile); - StreamResult result = new StreamResult(writer); - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - transformer.transform(source, result); } } diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java index 3f9a23d58..644031e9a 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/TicketUtils.java @@ -19,10 +19,7 @@ import java.awt.event.HierarchyListener; import java.io.IOException; import java.net.URISyntaxException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; +import java.security.GeneralSecurityException; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; @@ -56,7 +53,7 @@ public static boolean isTicketSet(Project project) { return ticket != null && !ticket.isEmpty(); } - public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + public static boolean isTicketValid(Project project, ProgressStatus progressStatus) throws ServerException, IOException, URISyntaxException, GeneralSecurityException { if (!isTicketSet(project)) { return false; } @@ -247,7 +244,7 @@ private static boolean acquireTicket(Project project, String pass) { String ticket; try { ticket = MMSUtils.getCredentialsTicket(project, username, pass, progressStatus); - } catch (IOException | URISyntaxException | ServerException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + } catch (IOException | URISyntaxException | ServerException | GeneralSecurityException e) { Application.getInstance().getGUILog().log("[ERROR] An error occurred while acquiring credentials. Reason: " + e.getMessage()); e.printStackTrace(); return; diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java index 9ded36be2..4b6979e56 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/XMLUtil.java @@ -1,24 +1,29 @@ package gov.nasa.jpl.mbee.mdk.util; -import java.util.*; -import org.w3c.dom.*; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; -public final class XMLUtil { - private XMLUtil(){} +import java.util.AbstractList; +import java.util.Collections; +import java.util.List; +import java.util.RandomAccess; +public final class XMLUtil { public static List asList(NodeList n) { - return n.getLength()==0? - Collections.emptyList(): new NodeListWrapper(n); + return n.getLength() == 0 ? Collections.emptyList() : new NodeListWrapper(n); } - static final class NodeListWrapper extends AbstractList - implements RandomAccess { + + static final class NodeListWrapper extends AbstractList implements RandomAccess { private final NodeList list; + NodeListWrapper(NodeList l) { - list=l; + list = l; } + public Node get(int index) { return list.item(index); } + public int size() { return list.getLength(); } diff --git a/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java b/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java index 242215262..22a34154b 100644 --- a/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java +++ b/src/test/java/gov/nasa/jpl/mbee/mdk/test/framework/MagicDrawClassLoaderWorker.java @@ -19,18 +19,35 @@ import org.gradle.api.Action; import org.gradle.api.logging.LogLevel; import org.gradle.internal.UncheckedException; +import org.gradle.internal.concurrent.ExecutorFactory; +import org.gradle.internal.event.DefaultListenerManager; +import org.gradle.internal.event.ListenerManager; import org.gradle.internal.io.ClassLoaderObjectInputStream; -import org.gradle.internal.serialize.Decoder; -import org.gradle.internal.serialize.InputStreamBackedDecoder; import org.gradle.internal.logging.LoggingManagerInternal; import org.gradle.internal.logging.services.LoggingServiceRegistry; import org.gradle.internal.remote.MessagingClient; import org.gradle.internal.remote.ObjectConnection; -import org.gradle.internal.remote.services.MessagingServices; import org.gradle.internal.remote.internal.inet.MultiChoiceAddress; import org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer; -import org.gradle.process.internal.worker.child.ApplicationClassesInSystemClassLoaderWorkerFactory; +import org.gradle.internal.remote.services.MessagingServices; +import org.gradle.internal.serialize.Decoder; +import org.gradle.internal.serialize.InputStreamBackedDecoder; +import org.gradle.internal.service.DefaultServiceRegistry; +import org.gradle.internal.service.ServiceRegistry; +import org.gradle.process.internal.health.memory.DefaultJvmMemoryInfo; +import org.gradle.process.internal.health.memory.DefaultMemoryManager; +import org.gradle.process.internal.health.memory.DisabledOsMemoryInfo; +import org.gradle.process.internal.health.memory.JvmMemoryInfo; +import org.gradle.process.internal.health.memory.JvmMemoryStatus; +import org.gradle.process.internal.health.memory.JvmMemoryStatusListener; +import org.gradle.process.internal.health.memory.MemoryManager; +import org.gradle.process.internal.health.memory.OsMemoryInfo; +import org.gradle.process.internal.worker.WorkerLoggingSerializer; +import org.gradle.process.internal.worker.WorkerJvmMemoryInfoSerializer; import org.gradle.process.internal.worker.child.WorkerContext; +import org.gradle.process.internal.worker.child.WorkerJvmMemoryInfoProtocol; +import org.gradle.process.internal.worker.child.WorkerLogEventListener; +import org.gradle.process.internal.worker.child.WorkerLoggingProtocol; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -65,25 +82,35 @@ public Void call() throws Exception { LoggingManagerInternal loggingManager = createLoggingManager(); loggingManager.setLevelInternal(LogLevel.values()[logLevel]).start(); + // Read whether process info should be published + boolean shouldPublishJvmMemoryInfo = decoder.readBoolean(); + // Read server address and start connecting MultiChoiceAddress serverAddress = new MultiChoiceAddressSerializer().read(decoder); - MessagingServices messagingServices = createClient(); + MessagingServices messagingServices = new MessagingServices(); + MagicDrawClassLoaderWorker.WorkerServices workerServices = new MagicDrawClassLoaderWorker.WorkerServices(messagingServices); + WorkerLogEventListener workerLogEventListener = null; try { + // Read serialized worker + byte[] serializedWorker = decoder.readBinary(); + + // Deserialize the worker action + Action action; + try { + ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader()); + action = (Action) instr.readObject(); + } catch (Exception e) { + throw UncheckedException.throwAsUncheckedException(e); + } + final ObjectConnection connection = messagingServices.get(MessagingClient.class).getConnection(serverAddress); + workerLogEventListener = configureLogging(loggingManager, connection); + if (shouldPublishJvmMemoryInfo) { + configureWorkerJvmMemoryInfoEvents(workerServices, connection); + } try { - // Read serialized worker - byte[] serializedWorker = decoder.readBinary(); - - // Deserialize the worker action - Action action; - try { - ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader()); - action = (Action) instr.readObject(); - } catch (Exception e) { - throw UncheckedException.throwAsUncheckedException(e); - } action.execute(new WorkerContext() { public ClassLoader getApplicationClassLoader() { //return ClassLoader.getSystemClassLoader(); @@ -99,17 +126,60 @@ public ObjectConnection getServerConnection() { connection.stop(); } } finally { + if (workerLogEventListener != null) { + loggingManager.removeOutputEventListener(workerLogEventListener); + } messagingServices.close(); + loggingManager.stop(); } return null; } - MessagingServices createClient() { - return new MessagingServices(); + private WorkerLogEventListener configureLogging(LoggingManagerInternal loggingManager, ObjectConnection connection) { + connection.useParameterSerializers(WorkerLoggingSerializer.create()); + WorkerLoggingProtocol workerLoggingProtocol = connection.addOutgoing(WorkerLoggingProtocol.class); + WorkerLogEventListener workerLogEventListener = new WorkerLogEventListener(workerLoggingProtocol); + loggingManager.addOutputEventListener(workerLogEventListener); + return workerLogEventListener; + } + + private void configureWorkerJvmMemoryInfoEvents(MagicDrawClassLoaderWorker.WorkerServices services, ObjectConnection connection) { + connection.useParameterSerializers(WorkerJvmMemoryInfoSerializer.create()); + final WorkerJvmMemoryInfoProtocol workerJvmMemoryInfoProtocol = connection.addOutgoing(WorkerJvmMemoryInfoProtocol.class); + services.get(MemoryManager.class).addListener(new JvmMemoryStatusListener() { + @Override + public void onJvmMemoryStatus(JvmMemoryStatus jvmMemoryStatus) { + workerJvmMemoryInfoProtocol.sendJvmMemoryStatus(jvmMemoryStatus); + } + }); } LoggingManagerInternal createLoggingManager() { - return LoggingServiceRegistry.newCommandLineProcessLogging().newInstance(LoggingManagerInternal.class); + LoggingManagerInternal loggingManagerInternal = LoggingServiceRegistry.newEmbeddableLogging().newInstance(LoggingManagerInternal.class); + loggingManagerInternal.captureSystemSources(); + return loggingManagerInternal; + } + + private static class WorkerServices extends DefaultServiceRegistry { + public WorkerServices(ServiceRegistry... parents) { + super(parents); + } + + ListenerManager createListenerManager() { + return new DefaultListenerManager(); + } + + OsMemoryInfo createOsMemoryInfo() { + return new DisabledOsMemoryInfo(); + } + + JvmMemoryInfo createJvmMemoryInfo() { + return new DefaultJvmMemoryInfo(); + } + + MemoryManager createMemoryManager(OsMemoryInfo osMemoryInfo, JvmMemoryInfo jvmMemoryInfo, ListenerManager listenerManager, ExecutorFactory executorFactory) { + return new DefaultMemoryManager(osMemoryInfo, jvmMemoryInfo, listenerManager, executorFactory); + } } } From ba1f3458c0f1ff705563b59d6196f636d928de09 Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 20:39:46 -0700 Subject: [PATCH 04/11] Fix unclosed resources --- .../java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java index 97a0ec553..fa1f3cfaf 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java @@ -22,10 +22,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.awt.event.ActionEvent; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.util.*; /** @@ -198,19 +195,18 @@ public static void exportSVG(File svgFile, DiagramPresentationElement diagramPre String originalSvgEnrichedExportPropertyValue = System.getProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME); System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); - try { + try (InputStream svgInputStream = new FileInputStream(svgFile); Writer svgWriter = new FileWriter(svgFile)) { ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); String parser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - Document svg = f.createDocument(null, new FileInputStream(svgFile)); + Document svg = f.createDocument(null, svgInputStream); XMLUtil.asList(svg.getElementsByTagName("g")).stream() .filter(g -> g instanceof org.w3c.dom.Element) .map(g -> (org.w3c.dom.Element) g) .filter(g -> Objects.equals(g.getAttribute("class"), "element")) .forEach(g -> g.setAttribute("stroke-width", "0px")); DOMSource source = new DOMSource(svg); - FileWriter writer = new FileWriter(svgFile); - StreamResult result = new StreamResult(writer); + StreamResult result = new StreamResult(svgWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); From 3b81b937d0538e5f3ec9930161e80285c2c069fb Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 20:48:45 -0700 Subject: [PATCH 05/11] Make API base path modification null-safe --- src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index 0a8644e52..2d399b4b3 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -53,10 +53,7 @@ import java.net.URISyntaxException; import java.security.GeneralSecurityException; import java.security.KeyStore; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -644,7 +641,8 @@ private static URIBuilder getServiceUri(Project project, String baseUrl) { e.printStackTrace(); return null; } - uri.setPath((uri.getPath().endsWith("/") ? "" : "/") + "alfresco/service"); + String currentPath = Optional.ofNullable(uri.getPath()).orElse(""); + uri.setPath(currentPath + (currentPath.endsWith("/") ? "" : "/") + "alfresco/service"); if (project != null && TicketUtils.isTicketSet(project)) { uri.setParameter("alf_ticket", TicketUtils.getTicket(project)); } From 068264771b507167e76f8f2668bb29e6f520df9b Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 20:54:54 -0700 Subject: [PATCH 06/11] Revert self-signed cert prototype --- .../gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index 2d399b4b3..a67711b97 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -385,24 +385,10 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog Application.getInstance().getGUILog().log(requestSummary); } - KeyStore trustStore = KeyStore.getInstance("JKS"); - FileInputStream fis = new FileInputStream("./certs/cacerts.jks"); - trustStore.load(fis, "changeit".toCharArray()); - fis.close(); - SSLContext sslContext = SSLContexts.custom() - .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) // use null as second param if you don't have a separate key password - .build(); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - sslContext, new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}, null, - new DefaultHostnameVerifier() - ); - // create client, execute request, parse response, store in thread safe buffer to return as string later // client, response, and reader are all auto closed after block if (progressStatus == null) { - try (CloseableHttpClient httpclient = HttpClients.custom() - .setSSLSocketFactory(sslsf) - .build(); + try (CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpResponse response = httpclient.execute(request); InputStream inputStream = response.getEntity().getContent()) { responseCode.set(response.getStatusLine().getStatusCode()); @@ -420,9 +406,7 @@ public static File sendMMSRequest(Project project, HttpRequestBase request, Prog LAST_EXCEPTION.set(null); progressStatus.setIndeterminate(true); Future future = TaskRunner.runWithProgressStatus(() -> { - try (CloseableHttpClient httpclient = HttpClients.custom() - .setSSLSocketFactory(sslsf) - .build(); + try (CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpResponse response = httpclient.execute(request); InputStream inputStream = response.getEntity().getContent()) { responseCode.set(response.getStatusLine().getStatusCode()); From 42cf6228f6b09bd7308a981b01f70abd01945229 Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 20:57:23 -0700 Subject: [PATCH 07/11] Remove unused imports after reverting self-signed cert prototype --- src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index a67711b97..053a37f4e 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -35,24 +35,18 @@ import org.apache.http.client.entity.EntityBuilder; import org.apache.http.client.methods.*; import org.apache.http.client.utils.URIBuilder; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.entity.ContentType; import org.apache.http.entity.FileEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; -import javax.net.ssl.SSLContext; import javax.swing.*; import java.io.*; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; import java.security.GeneralSecurityException; -import java.security.KeyStore; import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; From 30109fb00baa81a98cb356356da88152af918ffa Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Wed, 15 Jul 2020 21:05:18 -0700 Subject: [PATCH 08/11] Add uncaught exception --- src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java index 1be8b4206..30a70b614 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/docgen/DocGenUtils.java @@ -449,7 +449,7 @@ public static List exportDiagram(Diagram diagram, File directory) throws try { MDUtils.exportSVG(svgDiagramFile, diagramPresentationElement); ImageExporter.export(diagramPresentationElement, ImageExporter.PNG, pngDiagramFile, false, DOCGEN_DIAGRAM_DPI, DOCGEN_DIAGRAM_SCALE_PERCENT); - } catch (IOException e) { + } catch (IOException | TransformerException e) { e.printStackTrace(); return results; } From 35c5f99266afbc1c0d69232b29c3201f939a4023 Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Mon, 20 Jul 2020 13:23:14 -0700 Subject: [PATCH 09/11] Address case where MMS URL has full path --- src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java index 053a37f4e..0e99b6ada 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java @@ -619,8 +619,14 @@ private static URIBuilder getServiceUri(Project project, String baseUrl) { e.printStackTrace(); return null; } - String currentPath = Optional.ofNullable(uri.getPath()).orElse(""); - uri.setPath(currentPath + (currentPath.endsWith("/") ? "" : "/") + "alfresco/service"); + String path = Optional.ofNullable(uri.getPath()).orElse(""); + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + if (!path.endsWith("alfresco/service")) { + path += "/alfresco/service"; + } + uri.setPath(path); if (project != null && TicketUtils.isTicketSet(project)) { uri.setParameter("alf_ticket", TicketUtils.getTicket(project)); } From 8ad43120ee9ee8caf1f2b55d58036b7e7236adf8 Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Tue, 21 Jul 2020 10:33:10 -0700 Subject: [PATCH 10/11] Make SVG enriched export property static --- src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java index fa1f3cfaf..0de8fff73 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/util/MDUtils.java @@ -31,6 +31,8 @@ */ public class MDUtils { + public static String SVG_ENRICHED_EXPORT_PROPERTY_NAME = "svg.enriched.export"; + /** * @return true iff MD was started with the DEVELOPER option at the command * line. @@ -191,7 +193,6 @@ public static long getRemoteVersion(Project project) { } public static void exportSVG(File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException { - String SVG_ENRICHED_EXPORT_PROPERTY_NAME = "svg.enriched.export"; String originalSvgEnrichedExportPropertyValue = System.getProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME); System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(!diagramPresentationElement.getDiagramType().getRootType().equals(com.nomagic.magicdraw.uml.DiagramTypeConstants.DEPENDENCY_MATRIX))); From 8a86375da6fd8bfbca0e98a022da47b9d4315078 Mon Sep 17 00:00:00 2001 From: Enquier Date: Tue, 21 Jul 2020 11:58:39 -0600 Subject: [PATCH 11/11] Update version for 4.4.0 release --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4de47ab51..23bbd3f86 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=4.3.1 +version=4.4.0 group=org.openmbee.magicdraw.mdk descriptorFile=MDR_Plugin_Model_Development_Kit_91110_descriptor.xml magicdDrawGroupName=gov.nasa.jpl.cae.magicdraw.mdk