-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command to export the module database into a file
Currently if one has a problematic resolver state it is very hard to provide a reproducing test case for analysis. This adds a new command exportFrameworkState that allows to export the module database (optional with its wiring state) into a file that later can be loaded for example in a test case to analyze it further.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
....eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ExportStateCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.equinox.console.commands; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.Dictionary; | ||
import java.util.Hashtable; | ||
|
||
import org.apache.felix.service.command.CommandProcessor; | ||
import org.apache.felix.service.command.CommandSession; | ||
import org.apache.felix.service.command.Descriptor; | ||
import org.eclipse.osgi.container.ModuleDatabase; | ||
import org.osgi.framework.BundleContext; | ||
|
||
public class ExportStateCommand { | ||
|
||
private BundleContext context; | ||
|
||
public ExportStateCommand(BundleContext context) { | ||
this.context = context; | ||
} | ||
|
||
public void startService() { | ||
Dictionary<String, Object> dict = new Hashtable<>(); | ||
dict.put(CommandProcessor.COMMAND_SCOPE, "export"); | ||
dict.put(CommandProcessor.COMMAND_FUNCTION, new String[] { "exportFrameworkState" }); | ||
context.registerService(ExportStateCommand.class, this, dict); | ||
} | ||
|
||
@Descriptor("Exports the current framework state including the wiring information") | ||
public void exportFrameworkState(CommandSession session, String path) throws IOException { | ||
exportFrameworkState(session, path, true); | ||
} | ||
|
||
@Descriptor("Exports the current framework state, with or without the wiring information") | ||
public void exportFrameworkState(CommandSession session, String path, boolean persitWirings) throws IOException { | ||
ModuleDatabase database = context.getBundle(0).adapt(ModuleDatabase.class); | ||
PrintStream console = session.getConsole(); | ||
if (database != null) { | ||
File file = new File(path); | ||
console.println("Exporting ModuleDatabase to " + file.getAbsolutePath() + "..."); | ||
try (DataOutputStream stream = new DataOutputStream(new FileOutputStream(file))) { | ||
database.store(stream, persitWirings); | ||
} | ||
} else { | ||
console.println("Can't determine ModuleDatabase!"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters