How to call an exist format function within eclipse for the code file which i created by my plugin? - eclipse

I wrote an eclipse plugin which can be used create JavaScript file with template codes in it.
Currently i am using JavaScript Development Tools, it includes the formatter feature.
What i want is, once my plugin created a new JavaScript file(it's written in one line without formatted), I want to call the formatter function in my plugin to format the code immediately.
Is it possible to do this?

I am using org.eclipse.wst.jsdt.feature plugin.
The usage of formatting JavaScript code programmatically is the same as the way to do with Java code.
as following:
Map<?, ?> setting = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
CodeFormatter formatter = ToolFactory.createCodeFormatter(setting);
TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, js,
0, js.length(), 0, StringUtil.NEW_LINE);
if (edit == null)
return js;
IDocument doc = new Document(js);
try {
edit.apply(doc);
} catch (Exception e) {
e.printStackTrace();
return js;
}
return doc.get();
The thing you need mention is, you need import following package from org.eclipse.wst.jsdt.
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.wst.jsdt.core.ToolFactory;
import org.eclipse.wst.jsdt.core.formatter.CodeFormatter;
import org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants;

Related

How to solve "BetaAnalyticsDataClient cannot be resolved"?

I tried sample source at Google Analytics Data API (GA4), there is code as below:
import com.google.analytics.data.v1beta.BetaAnalyticsDataClient;
....
try (BetaAnalyticsDataClient analyticsData = BetaAnalyticsDataClient.create()) {
RunReportRequest request = RunReportRequest.newBuilder()
.setProperty("properties/" + propertyId)
.addDimensions(Dimension.newBuilder().setName("city"))
.addMetrics(Metric.newBuilder().setName("activeUsers"))
.addDateRanges(DateRange.newBuilder().setStartDate("2020-03-31").setEndDate("today"))
.build();
...
Though I import jar files with
compile 'com.google.api.grpc:proto-google-analytics-data-v1beta:0.10.2'
compile 'com.google.apis:google-api-services-analyticsdata:v1beta-rev20220504-1.32.1'
I still got error "BetaAnalyticsDataClient cannot be resolved", how can I solve this problem?

Can we link external API for a confluence page?

I have a requirement where when the user clicks publish button in a Confluence page, need to trigger an external API (post endpoint ) where I can save confluence data in external DB.
Have a look at the Event Listener module and How to build an Event Listener. Basically, you create a plugin that captures the com.atlassian.confluence.event.events.content.page.PageEvent. In your case, you might use PageCreateEvent or PageUpdateEvent. This is for Confluence Server. As for Confluence Cloud, it might be in JavaScript or something.
If you don't feel like developing an addon for it,
then i recommend using an addon adaptavist scriprunner :
that's the easiest way to accomplish that (although not free!)
example from their webpage:
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.confluence.event.events.space.SpaceCreateEvent
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import
static com.atlassian.sal.api.net.Request.MethodType.POST
def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
def event = event as SpaceCreateEvent
def space = event.space
def input = new JsonBuilder([
projectTypeKey : "business",
projectTemplateKey: "com.atlassian.jira-core-project-templates:jira-core-task-management",
name : space.name,
key : space.key,
lead : event.space.creator.name,
]).toString()
def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/project")
.addHeader("Content-Type", "application/json")
.setEntity(input)
request.execute(new ResponseHandler<Response>() {
#Override
void handle(Response response) throws ResponseException {
if (response.statusCode != 201) {
log.error("Creating jira project failed: ${response.responseBodyAsString}")
}
}
})

Is it possible to create a file with all my functions and read from from it in my specs?

I have some specs that are using the same functions, I would like to make one single file only for functions and read from this file while executing my scripts, would be that possible? if so.. how to do that?
During google searchers I found the "exports" to add in config file but didn't work (also I don't know how to call it from the config)
For example, I would like to add 2 functions in my config file (or separated file only for functions) and during any point of my execution, call it from the spec file:
function loginAdminUser(userElement, passWordElement, userName, password){
var loginButton = element(by.id('logIn'));
browser.get('https://( ͡° ͜ʖ ͡°).com/');
userElement.sendKeys(userName);
passWordElement.sendKeys(password);
loginButton.click();
}
function accessHistoryViewDetail(){
menuForViews.then(function(selectview) {
selectview[3].click();
browser.sleep(500);
});
}
1 - How can I do that? (using "Suites" would be an option?)
2 - How to call them in my specs?
Thank you and have a good day!
As far as I know you cannot add utility functions that you want to use in your tests in the config file. The options in the config file are generally for setting up the testing environment.
You can however put your functions in a separate file and import that to use the functions. Below is an example of how to do that using js and Node's module exports, you can do something similar with ts using classes.
// utils.js
function loginAdminUser(userElement, passWordElement, userName, password){
var loginButton = element(by.id('logIn'));
browser.get('https://( ͡° ͜ʖ ͡°).com/'); // nice Lenny face :)
userElement.sendKeys(userName);
passWordElement.sendKeys(password);
loginButton.click();
}
function accessHistoryViewDetail() {
menuForViews.then(function(selectview) {
selectview[3].click();
browser.sleep(500);
});
}
module.exports = {
loginAdminUserloginAdminUser: loginAdminUser,
accessHistoryViewDetail: accessHistoryViewDetail
}
Then in your spec file
import * as utils from './utils.js';
...
it('should ...', () => {
...
utils.accessHistoryViewDetail();
...
});
});
I hope that helps.

using Axe-core inside Intern 4

I am trying to set up my accessibility testing using axe-core or axe-webdriverjs inside of Intern 4. I finally got something to compile but I get this socket hung up error. Let me walk you through my process.
Loading axe-core as a plugin. In my intern.json
I have my included a plugin axe-core. node_modules/axe-core/axe.min.js specified here https://axe-core.org/. This did not work. When running the test it did not find the module.
I then tried using the loader to import this module. In my intern.json I had the following:
"plugins": [
"node_modules/babel-register/lib/node.js"
],
installed the necessary plugins and then I imported axe in my test.js using:
`import axe from '/node_modules/axe-core/axe.min'`
still I get axe is undefined errors.
I tried to use axe-webdriverjs used the example code
const { suite, test, before } = intern.getInterface('tdd');
const { assert } = intern.getPlugin('chai');
var AxeBuilder = require('axe-webdriverjs');
var time = 1000;
var session;
suite('Accessibility', () => {
test('Accessibility Test 1', ({remote}) => {
remote.get('https://dequeuniversity.com/demo/mars/')
.then(function () {
AxeBuilder(driver)
.analyze(function (results) {
console.log(results);
});
});
});
});
still could not get it to work.
then I tried changing the
var AxeBuilder = require('axe-webdriverjs');
to
import AxeBuilder from 'node_modules/axe-webdriverjs/lib/index';
It is now running but I get a socket hang up error.
All I am trying to do is run axe-core or even axe-webdriver a thrid party library into tests suite within intern 4. Any sort of help will be appreciated.
Thanks
There is an Intern accessibility plugin that includes support for aXe. You can use that directly, or simply use it as an example of how to use aXe-core with Intern.
You wouldn't typically use axe-webdriverjs with Intern since Intern is using its own WebDriver library which isn't directly compatible with the Selenium JS library.

Netbeans plugin (read code)

I make a basic plugin on netbeans 8.0.2 and I'm a little confused because I want to read the code in some way to provide errors or other notifications to the user you are writing code but not how.
This should print out all the text in all the open windows.
TopComponent tcArray[] = WindowManager.getDefault().findMode("editor").getTopComponents();
for (TopComponent tc : tcArray) {
System.out.println("tc = " + tc);
Collection<? extends FileObject> fileobjs = tc.getLookup().lookupAll(FileObject.class);
for (FileObject fo : fileobjs) {
try {
String text = fo.asText();
System.out.println("text = " + text);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
In order to use it you need the following modules added as dependencies.
File System API
Lookup API
Utilities API
Window System API