private void createActions(IToolBarManager manager) { Action publishAction = new Action("Publish to DAWN marketplace", Action.AS_PUSH_BUTTON) { @Override public ImageDescriptor getImageDescriptor() { return Activator.getImageDescriptor("icons/publish.png"); } @Override public void run() { OverviewPage.this.getManagedForm().getMessageManager().removeAllMessages(); try { scheduleExportJob(); } catch (IOException e) { OverviewPage.this.getManagedForm().getMessageManager().addMessage(MPC, e.getMessage(), null, IMessage.ERROR); } } }; manager.add(publishAction); manager.update(true); }
public void update() { if (controlMessages.isEmpty()) { decoration.setDescriptionText(null); decoration.hide(); } else { final ArrayList peers = createPeers(controlMessages); final int type = ((IMessage) peers.get(0)).getMessageType(); final String description = createDetails(createPeers(peers), true); if (type == IMessageProvider.ERROR) decoration.setImage(standardError.getImage()); else if (type == IMessageProvider.WARNING) decoration.setImage(standardWarning.getImage()); else if (type == IMessageProvider.INFORMATION) decoration.setImage(standardInformation.getImage()); decoration.setDescriptionText(description); decoration.show(); } }
private void update(final ArrayList mergedList) { pruneControlDecorators(); if (scrolledForm.getHead().getBounds().height == 0 || mergedList.isEmpty() || mergedList == null) { scrolledForm.setMessage(null, IMessageProvider.NONE); return; } final ArrayList peers = createPeers(mergedList); final int maxType = ((IMessage) peers.get(0)).getMessageType(); String messageText; final IMessage[] array = (IMessage[]) peers.toArray(new IMessage[peers.size()]); if (peers.size() == 1 && ((Message) peers.get(0)).prefix == null) { // a single message final IMessage message = (IMessage) peers.get(0); messageText = message.getMessage(); scrolledForm.setMessage(messageText, maxType, array); } else { // show a summary message for the message // and list of errors for the details if (peers.size() > 1) messageText = Messages.bind(MULTIPLE_MESSAGE_SUMMARY_KEYS[maxType], new String[] { peers.size() + "" }); //$NON-NLS-1$ else messageText = SINGLE_MESSAGE_SUMMARY_KEYS[maxType]; scrolledForm.setMessage(messageText, maxType, array); } }
private void configureFormText(final Form form, FormText text) { text.addHyperlinkListener(new HyperlinkAdapter() { @SuppressWarnings("unchecked") public void linkActivated(HyperlinkEvent e) { String is = (String) e.getHref(); try { ((FormText) e.widget).getShell().dispose(); int index = Integer.parseInt(is); IMessage[] messages = form.getChildrenMessages(); IMessage message = messages[index]; Set<IvyNodeElement> conflicts = (Set<IvyNodeElement>) message.getData(); if (conflicts != null) { viewer.setSelection(new StructuredSelection(new ArrayList<>(conflicts))); } } catch (NumberFormatException ex) { } } }); text.setImage("error", getImage(IMessageProvider.ERROR)); text.setImage("warning", getImage(IMessageProvider.WARNING)); text.setImage("info", getImage(IMessageProvider.INFORMATION)); }
protected void uploadFile(CloseableHttpClient client, Path path, String segment) throws ClientProtocolException, IOException { String token = getCsrfToken(client); String url = getMarketplaceUrl(); // upload the p2-repository file HttpPost httpPost = new HttpPost(url + "/"+segment); httpPost.addHeader(X_CSRF_TOKEN, token); HttpEntity file = MultipartEntityBuilder .create() .addBinaryBody("file", path.toFile()) .addTextBody("id", solution.getId().toString()) .build(); httpPost.setEntity(file); HttpResponse response = client.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { String result = EntityUtils.toString(response.getEntity()); // obtain some key values from the server version // and update the local instance Node node = MarketplaceSerializer.deSerializeSolution(result); solution.setChanged(node.getChanged()); addMessage(IMessage.INFORMATION, "File "+path.getFileName()+" uploaded"); } else { String reasonPhrase = response.getStatusLine().getReasonPhrase(); addMessage(IMessage.ERROR, reasonPhrase); } }
private void uploadForm(CloseableHttpClient client) throws ClientProtocolException, IOException, UnsupportedEncodingException { OverviewPage.this.getManagedForm().getMessageManager().removeMessage(MPC); String token = getCsrfToken(client); String url = getMarketplaceUrl(); // upload the form HttpPost httpPost = new HttpPost(url + "/upload"); httpPost.addHeader(X_CSRF_TOKEN, token); HttpEntity entity = new ByteArrayEntity( MarketplaceSerializer.serialize(solution).getBytes("UTF-8")); httpPost.setEntity(entity); HttpResponse response = client.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { String result = EntityUtils.toString(response.getEntity()); // obtain some key values from the server version // and update the local instance Node node = MarketplaceSerializer.deSerializeSolution(result); solution.setId(node.getId()); solution.setChanged(node.getChanged()); solution.setCreated(node.getCreated()); addMessage(IMessage.INFORMATION, "Solution uploaded"); } else { String reasonPhrase = response.getStatusLine().getReasonPhrase(); addMessage(IMessage.ERROR, reasonPhrase); } }
public static String createDetails(final IMessage[] messages) { if (messages == null || messages.length == 0) return null; final StringWriter sw = new StringWriter(); final PrintWriter out = new PrintWriter(sw); for (int i = 0; i < messages.length; i++) { if (i > 0) out.println(); out.print(getFullMessage(messages[i])); } out.flush(); return sw.toString(); }
private String createDetails(final ArrayList messages, final boolean excludePrefix) { final StringWriter sw = new StringWriter(); final PrintWriter out = new PrintWriter(sw); for (int i = 0; i < messages.size(); i++) { if (i > 0) out.println(); final IMessage m = (IMessage) messages.get(i); out.print(excludePrefix ? m.getMessage() : getFullMessage(m)); } out.flush(); return sw.toString(); }
String createFormTextContent(IMessage[] messages) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<form>"); for (int i = 0; i < messages.length; i++) { IMessage message = messages[i]; pw.print("<li vspace=\"false\" style=\"image\" indent=\"16\" value=\""); switch (message.getMessageType()) { case IMessageProvider.ERROR: pw.print("error"); break; case IMessageProvider.WARNING: pw.print("warning"); break; case IMessageProvider.INFORMATION: pw.print("info"); break; } pw.print("\"> <a href=\""); pw.print(i + ""); pw.print("\">"); if (message.getPrefix() != null) { pw.print(message.getPrefix()); } pw.print(message.getMessage()); pw.println("</a></li>"); } pw.println("</form>"); pw.flush(); return sw.toString(); }
private void evalFormulas() { form.getMessageManager().removeAllMessages(); List<String> errors = Formulas.eval(parameters); hasErrors = errors.size() > 0; for (String error : errors) form.getMessageManager() .addMessage("invalidFormula", M.InvalidFormula + ": " + error, null, IMessage.ERROR); }
protected void scheduleExportJob() throws IOException { Path folder = Files.createTempDirectory("eclipse-export", new FileAttribute<?>[0]); final FeatureExportInfo info = new FeatureExportInfo(); info.toDirectory = false; // in order to install from the repository info.useJarFormat = true; info.exportSource = false; info.exportSourceBundle = false; info.allowBinaryCycles = true; info.useWorkspaceCompiledClasses = false; info.destinationDirectory = folder.toString(); info.zipFileName = "p2-repo.zip"; info.items = getFeatures(); info.signingInfo = null; // info.exportMetadata = true; info.qualifier = QualifierReplacer.getDateQualifier(); final FeatureExportOperation job = new FeatureExportOperation(info, PDEUIMessages.FeatureExportJob_name); job.setUser(true); job.setRule(ResourcesPlugin.getWorkspace().getRoot()); job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_PLUGIN_OBJ); // listen to job changes, we'll upload stuff when the building has been done job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (job.hasAntErrors()) { // if there were errors when running the ant scripts, inform // the user where the logs can be found. final File logLocation = new File(info.destinationDirectory, "logs.zip"); //$NON-NLS-1$ if (logLocation.exists()) { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AntErrorDialog dialog = new AntErrorDialog(logLocation); dialog.open(); } }); } } else if (event.getResult().isOK()) { // can publish try (CloseableHttpClient client = HttpClientBuilder.create().build()) { // sign in and upload items if (signIn(client)) { uploadForm(client); // upload the images if (solution.getScreenshot() != null) { uploadFile(client, Paths.get(solution.getScreenshot()), "upload-screenshot"); } if (solution.getImage() != null) { uploadFile(client, Paths.get(solution.getImage()), "upload-image"); } // upload the repository uploadFile(client, folder.resolve("p2-repo.zip"),"upload-p2repo"); } } catch (Exception e) { e.printStackTrace(); addMessage(IMessage.ERROR, e.getMessage()); } } } }); job.schedule(); }
private static String getFullMessage(final IMessage message) { if (message.getPrefix() == null) return message.getMessage(); return message.getPrefix() + message.getMessage(); }
public String createSummary(final IMessage[] messages) { return createDetails(messages); }