IArtifactRepositoryManager is null with Eclipse Oxygen 4.7.2 - eclipse-rcp

The following function worked perfectly in Eclipse Neon 4.6.x target runtime for a very long time:
public static boolean addRepository(IProvisioningAgent agent, String repo) {
Utils.log(String.format("adding repository at %s", repo));
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
if (metadataManager == null || artifactManager == null) {
Utils.log("P2Utils.addRepository - missing metadata or artifact manager");
return false;
}
try {
URI uri = new URI(repo);
metadataManager.addRepository(uri);
artifactManager.addRepository(uri);
return true;
} catch (Exception e) {
Utils.log(e);
return false;
}
}
It stopped working with Eclipse Oxygen 4.7.2 target, the artifactManager returned is always null. Does anyone involved knows what was changed and how to fix this? It breaks our updates.., I am at a loss where to look.

Got the response from eclipse forum, there were some plugins missing:
org.eclipse.equinox.p2.artifact.repository
org.eclipse.equinox.p2.transport.ecf

Related

Eclipse Issue: P/tag_query, does not match outer scope rule

The eclipse platform for RCP product was upgraded from 3.6.2 to 4.6.3. The below code was working fine with 3.6.2:
public static ConfigTagService getTagService(MethodConfiguration config) {
delegate = ConfigurationHelper.getDelegate();
thisConfig = config;
if (delegate instanceof ConfigHelperDelegate) {
configTagService = ((ConfigHelperDelegate) delegate).getTagService_(thisConfig);
return configTagService;
}
return null;
}
But after upgrade I am getting issue with this code and subsequent calls to below line throws exception:
folder.refreshLocal(IResource.DEPTH_INFINITE, null);
The detailed stack trace is:
!MESSAGE An internal error occurred during: "Fetching children of view".
!STACK 0
java.lang.IllegalArgumentException: Attempted to beginRule: P/tag_query, does not match outer scope rule: com.eclipse.rmc.authoring.ui.providers.ConfigurationContentProvider$BatchSimilarSchedulingRule#f9cfe23e
at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
at org.eclipse.core.internal.jobs.ThreadJob.illegalPush(ThreadJob.java:134)
at org.eclipse.core.internal.jobs.ThreadJob.push(ThreadJob.java:333)
at org.eclipse.core.internal.jobs.ImplicitJobs.begin(ImplicitJobs.java:85)
at org.eclipse.core.internal.jobs.JobManager.beginRule(JobManager.java:307)
at org.eclipse.core.internal.resources.WorkManager.checkIn(WorkManager.java:121)
at org.eclipse.core.internal.resources.Workspace.prepareOperation(Workspace.java:2188)
at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1586)
at com.eclipse.rmc.library.tag.internal.TagService.initialize(TagService.java:546)
at com.eclipse.rmc.library.tag.internal.TagService.<init>(TagService.java:293)
at com.eclipse.rmc.library.tag.AbstractTagService.newInstance(AbstractTagService.java:42)
at com.eclipse.rmc.library.ConfigTagService.newTagService(ConfigTagService.java:82)
at com.eclipse.rmc.library.ConfigTagService.setConfig(ConfigTagService.java:72)
at com.eclipse.rmc.library.ConfigHelperDelegate.getTagService_(ConfigHelperDelegate.java:387)
at com.eclipse.rmc.library.ConfigHelperDelegate.getTagService(ConfigHelperDelegate.java:175)
at com.eclipse.rmc.library.configuration.DefaultElementRealizer.addExtraToManyFeatureValues(DefaultElementRealizer.java:76)
at com.eclipse.rmc.library.configuration.DefaultElementRealizer.addExtraFeatureValues(DefaultElementRealizer.java:52)
at org.eclipse.epf.library.configuration.ConfigurationHelper.calculateFeature(ConfigurationHelper.java:880)
at org.eclipse.epf.library.configuration.ConfigurationHelper.calc0nFeatureValue_(ConfigurationHelper.java:1577)
at org.eclipse.epf.library.configuration.ConfigurationHelper.calc0nFeatureValue(ConfigurationHelper.java:1533)
at org.eclipse.epf.library.configuration.ConfigurationHelper.calc0nFeatureValue(ConfigurationHelper.java:1514)
at org.eclipse.epf.library.configuration.ConfigurationFilter.getChildren(ConfigurationFilter.java:150)
at org.eclipse.epf.library.edit.internal.TngAdapterFactoryImpl$FilterItemProvider.getChildren_(TngAdapterFactoryImpl.java:394)
at org.eclipse.epf.library.edit.internal.TngAdapterFactoryImpl$FilterItemProvider.getChildren(TngAdapterFactoryImpl.java:368)
at org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider.getChildren(AdapterFactoryContentProvider.java:175)
at com.eclipse.rmc.authoring.ui.providers.ConfigurationContentProvider.fetchChildren(ConfigurationContentProvider.java:168)
at com.eclipse.rmc.authoring.ui.providers.ConfigurationContentProvider$DeferredItem.fetchDeferredChildren(ConfigurationContentProvider.java:103)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:231)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
I find the similar issue at https://www.eclipse.org/forums/index.php/t/442274/ and applied the solution to the causing issue as:
Job job = new Job("New job for tag query") {
#Override
protected IStatus run(IProgressMonitor monitor) {
configTagService = ((ConfigHelperDelegate) delegate).getTagService_(thisConfig);
return Status.OK_STATUS;
}
};
job.schedule();
With this fix, I do not get any exception and it works fine. However, for the large library, this the publish freezes with this fix. Could you please suggest alternative to avoid freeze issue?

Java WatchService code works in Eclipse but same code fails in Tomcat in Docker

In Eclipse, a unit test fires up this code and when the watched file is altered, outputs the new text.
In Tomcat, it hangs where shown.
I've grovelled around online for quite some time trying to find anyone with a similar problem, but nothing showed up.
This is vanilla watcher code, and because it works fine in Eclipse, there must be a Tomcat-specific issue, but what?
The file is accessible to the code in Tomcat. It's not a permissions problem.
public class Foo extends Thread {
File watchedFile = <the watched file>;
WatchService watcher = FileSystems.getDefault().newWatchService();
Path dir = watchedFile.getParentFile().toPath();
dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
#Override
public void run() {
while (true) {
WatchKey key;
try {
key = watcher().take(); <<< HANGS HERE IN TOMCAT, DOESN'T HANG HERE IN ECLIPSE.
} catch (InterruptedException | ClosedWatchServiceException e) {
break;
}
try {
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
if (kind == StandardWatchEventKinds.OVERFLOW) {
continue;
}
if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
WatchEvent<Path> pathEvent = (WatchEvent<Path>)event;
if (pathEvent.context().toString().equals(watchedFile.getName()) {
// Do something.
}
}
}
} catch (Exception e) {
throw new RuntimeException("Trouble: " + e.getMessage(), e);
}
if (!key.reset()) {
break;
}
}
}
}
UPDATE: . The problem was that I was writing to the file from outside Docker, so the change event wasn’t seen.
It’s similar to Java WatchService not generating events while watching mapped drives.

Wicket configuration for nashorn

I recently upgraded my java version from java 1.7 to java 1.8. After the upgrade i am getting this error.
Caused by: ECMAScript Exception: Type Error: Can not find a common class loader for ScriptObject and My Interface.
Which version of wicket do i need to use which supports java 1.8 and nashorn script engine. Also do i need to configure anything related to Script Engine for wicket.
I have tried adding this dependency
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-nashorn</artifactId>
<version>7.4.0</version>
</dependency>
and ScriptEngineManager sem = new ScriptEngineManager();
engine = sem.getEngineByName("nashorn");
but i am still getting the same issue.
Please help me fix this issue.
Below is my method
private final ScriptEngine engine;
ScriptEngineManager sem = new ScriptEngineManager();
engine = sem.getEngineByName("nashorn");
public <K> K getNewInterface(MyScript myScript){
ScriptContext ctx = new SimpleScriptContext();
String script = myScript.getScript();
if(Strings.isEmpty(script)) {markInvalid(myScript, "Script is empty", null); return null;}
script += " (function(){return this;})();";
Object thiz;
try{
thiz = engine.eval(script, ctx);
} catch (ScriptException e){
markInvalid(myScript, "Can't execute script", e);
return null;
}
if(thiz==null) {markInvalid(myScript, "Script executed, but context is null", null); return null;}
K ret = (K) ((Invocable)engine).getInterface(thiz, myScript.getScriptInterfaceClass());
if(ret==null) {
markInvalid(myScript, "Script executed, but it's incompatible with required interface", null);
return null;
}else{
myScript.setValid(true);
return ret;
}
}
Wicket doesn't need Nashorn. You can use Wicket 1.5/6.x/7.x/8.x with Java 8.
wicketstuff-nashorn is definitely not needed to run Wicket application.
Without the actual error it is hard for us to tell why it is failing.
Update: why do you use new ScriptEngineManager(null), i.e. null ClassLoader. Better use new ScriptEngineManager() and it will use the context class loader which most probably knows about both classes. Or use new ScriptEngineManager(YourInterface.class.getClassLoader())

Npgql get_HasRows() throwing ArgumentOutOfRangeException

Good afternoon,
I`m currently developing with AspNetCore and MVC and using PostgreSQL (Npgsql) as my database.
My queries are working fine when they have some result.
When the query returns empty results, I got an ArgumentOutOfRangeException error.
System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: Got unexpected message type: ReadyForQuery
in Npgsql.NpgsqlDataReader.get_HasRows()
in QueryPostgreSQL.IsEmpty()
in sistema_cotacao.Controllers.LoginController.<Index>d__2.MoveNext() in \Visual Studio 2015\Projects\sistema-cotacao\src\sistema-cotacao\Controllers\LoginController.cs:line 66
This is the code where the error occurs (At query.IsEmpty()):
if ((query.IsEmpty()) || (usuario.enti_email != usu.enti_email))
{
...
query.Close();
return View();
}
else
{
....
query.close();
return Redirect("/Login");
}
And my IsEmpty() function is:
private NpgsqlDataReader queryPostgreSQL;
...
public Boolean IsEmpty()
{
Boolean bResult = true;
bResult = !queryPostgreSQL.HasRows;
return bResult;
}
I couldn`t find where my problem is.
This is a bug in Npgsql. The issue has been fixed and will be released in version 3.1.7 (probably later today).

Eclipse RCP p2 update not working

I have a personal Eclipse RCP product (com.example.product) based on one personal feature (com.example.feature) which is composed of one personal plugin (com.example.plugin) and a bunch of others from Eclipse Helios (3.6). I want the app to check for updates and update itself if necessary from a p2 site. I want it to be headless, ie the user does not interact in the update process, but may see progress in a dialog.
I based my implementation for the updates on the RCP Mail application. I changed the P2Util.checkForUpdates method a bit to include some logging so I can see what, if anything, is going wrong there:
static IStatus checkForUpdates(IProvisioningAgent agent,
IProgressMonitor monitor) throws OperationCanceledException,
InvocationTargetException {
ProvisioningSession session = new ProvisioningSession(agent);
UpdateOperation operation = new UpdateOperation(session);
SubMonitor sub = SubMonitor.convert(monitor,
"Checking for application updates...", 200);
IStatus status = operation.resolveModal(sub.newChild(100));
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
return status;
}
if (status.getSeverity() == IStatus.CANCEL)
throw new OperationCanceledException();
if (status.getSeverity() != IStatus.ERROR) {
try {
logger.info( "Status is " + status );
Update[] updates = operation.getPossibleUpdates();
for( Update u : updates){
logger.info( "Update is " + u );
}
ProvisioningJob job = operation.getProvisioningJob(null);
if( job == null ){
logger.error( "Provisioning Job is null" );
}
status = job.runModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL) {
throw new OperationCanceledException();
}
} catch ( Exception e ){
logger.error( "Exception while trying to get updates", e);
}
}
return status;
}
I have a p2.inf file in my feature at the same level as my example.product file. It contains:
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository":
instructions.configure=\
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(type:0,location:file${#58}/C${#58}/workspace/updatesite/);\
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(type:1,location:file${#58}/C${#58}/workspace/updatesite/);
I build the product with plugin, feature and product IDs set to 1.0.0.
I can export and run my product from eclipse using the product export wizard. I tick generate metadata repository when I do this.
I create my update site using the Create an Update Site Project option in the Feature Manfiest Editor. I add my `com.example.feature' and build it. Just to see if it works I try browsing it via eclipse IDE Install New Software option and I can see the feature there.
I build the update site with all 3 IDs changed to 1.0.1. When I start the app it says there are no updates to install, there are no errors in the logs.
I don't know why it doesn't update from the update site, but things that have crossed my mind are:
1) I may need more info in the p2.inf file, but I'm not sure what, maybe something like namespace, name and range, but I can't find a good practical example.
2) In the checkForUpdates method I may need to do something with profiles to change what installable units are being updated. Again, I only found comments hinting at this and not any example code that shows how.
Any hints or ideas are much appreciated here, this is eating a lot of time.
Look at this code. Rebuild your product with a new product version and try to setup a http server. It didnt work with file repo for me. Just publishing the feature will not work.
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
sub = SubMonitor.convert(monitor, Messages.getString("UpdateManager.searchforupdates"), 200); //$NON-NLS-1$
final Update update = getUpdate(profile, provisioningContext, engine, context);
status = operation.resolveModal(sub.newChild(100));
LogHelper.log(status);
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
status = null;
return;
}
if (status.getSeverity() == IStatus.CANCEL)
throw new OperationCanceledException();
if (status.getSeverity() != IStatus.ERROR) {
log(IStatus.INFO, "Checking for available update matches", null); //$NON-NLS-1$
Update[] selected = new Update[1];
operation.setSelectedUpdates(new Update[0]);
for (Update available : operation.getPossibleUpdates()) {
if (available.equals(update)) {
log(IStatus.INFO, "Update matches available: " + update, null); //$NON-NLS-1$
selected[0] = available;
operation.setSelectedUpdates(selected);
}
}
if (selected[0] == null) {
status = null;
monitor.setCanceled(true);
log(IStatus.WARNING, "No Update matches selected", null); //$NON-NLS-1$
return;
}
ProvisioningJob job = operation.getProvisioningJob(monitor);
if (job != null) {
status = job.runModal(sub.newChild(100));
if (status.getSeverity() != IStatus.ERROR) {
prefStore.setValue(JUSTUPDATED, true);
Display.getDefault().syncExec(new Runnable() {
public void run() {
PlatformUI.getWorkbench().restart();
}
});
} else {
LogHelper.log(status);
}
} else {
log(IStatus.INFO, "getJob returned null", null); //$NON-NLS-1$
status = null;
}
if (status != null && status.getSeverity() == IStatus.CANCEL)
throw new OperationCanceledException();
}
}
};
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
new ProgressMonitorDialog(null).run(true, true, runnable);
} catch (InvocationTargetException x) {
log(IStatus.ERROR, "Runnable failure", x); //$NON-NLS-1$
} catch (InterruptedException e) {
}
}
});
#user473284's answer had some suggestions that I used but I don't know if they were definite requirements
1) using a local web server instead of trying to point to a file
2) Incrementing the product version and using the update repository generated by the export product wizard.
I never did find the implementation for the getUpdate method referenced from the code sample so I couldn't make use of the snippet.
After the above changes I was still left with the app detecting no updates on startup. Debugging showed that my repository was not showing up in the session. I had to explicitly add the update url in the code, despite having it in the p2.inf and in set in the feature manifest editor form field. Here's the code for this:
public static void addUpdateSite(IProvisioningAgent provisioningAgent)
throws InvocationTargetException {
// Load repository manager
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) provisioningAgent
.getService(IMetadataRepositoryManager.SERVICE_NAME);
if (metadataManager == null) {
logger.error( "Metadata manager was null");
Throwable throwable = new
Throwable("Could not load Metadata Repository Manager");
throwable.fillInStackTrace();
throw new InvocationTargetException(throwable);
}
// Load artifact manager
IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) provisioningAgent
.getService(IArtifactRepositoryManager.SERVICE_NAME);
if (artifactManager == null) {
logger.error( "Artifact manager was null");
Throwable throwable = new Throwable(
"Could not load Artifact Repository Manager");
throwable.fillInStackTrace();
throw new InvocationTargetException(throwable);
}
// Load repo
try {
URI repoLocation = new URI("http://localhost/respository");
logger.info( "Adding repository " + repoLocation );
metadataManager.loadRepository(repoLocation, null);
artifactManager.loadRepository(repoLocation, null);
} catch (ProvisionException pe) {
logger.error( "Caught provisioning exception " + pe.getMessage(), pe);
throw new InvocationTargetException(pe);
} catch (URISyntaxException e) {
logger.error( "Caught URI syntax exception " + e.getMessage(), e);
throw new InvocationTargetException(e);
}
}
I now call this first thing in the checkForUpdates method from the original question. After this change my app at least now sees the update and attempts to install it. I'm still having problem but that deserves a separate question of its own which I've created at https://stackoverflow.com/questions/3944953/error-during-p2-eclipse-rcp-app-headless-update
Web server is not mandatory, you can get updates with file location.
It is mandatory to change product version too.
You can't update those features with Update Site Project build which are exported with product, however you can do that with some hacking in exported product.
If you add some other features with (Install New Softwares) option then you can update these features with Update Site Project build.
Hopefully this will be helpful. If you need more clarification you can ask.