use of org.osmorc.facet.OsmorcFacet in project intellij-plugins by JetBrains.
the class AbstractOsgiQuickFix method getVerifiedManifestFile.
@Nullable
protected ManifestFile getVerifiedManifestFile(@NotNull PsiElement element) {
Module module = ModuleUtilCore.findModuleForPsiElement(element);
assert module != null : element;
OsmorcFacet facet = OsmorcFacet.getInstance(module);
if (facet != null) {
OsmorcFacetConfiguration configuration = facet.getConfiguration();
for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
VirtualFile file = root.findFileByRelativePath(configuration.getManifestLocation());
if (file != null) {
PsiFile psiFile = element.getManager().findFile(file);
if (psiFile instanceof ManifestFile && CommonRefactoringUtil.checkReadOnlyStatus(psiFile)) {
return (ManifestFile) psiFile;
}
}
}
}
OsmorcBundle.notification(getFamilyName(), OsmorcBundle.message("inspection.fix.no.manifest"), NotificationType.WARNING).notify(element.getProject());
return null;
}
use of org.osmorc.facet.OsmorcFacet in project intellij-plugins by JetBrains.
the class OsgiRunState method getSelectedBundles.
/**
* Here we got the magic. All libs are turned into bundles sorted and returned.
*/
private List<SelectedBundle> getSelectedBundles() throws ExecutionException {
final Ref<List<SelectedBundle>> result = Ref.create();
final Ref<ExecutionException> error = Ref.create();
ProgressManager.getInstance().run(new Task.Modal(myRunConfiguration.getProject(), "Preparing bundles...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(false);
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
Set<SelectedBundle> selectedBundles = new HashSet<>();
// the bundles are module names, by now we try to find jar files in the output directory which we can then install
ModuleManager moduleManager = ModuleManager.getInstance(myRunConfiguration.getProject());
BundleCompiler bundleCompiler = new BundleCompiler(progressIndicator);
int bundleCount = myRunConfiguration.getBundlesToDeploy().size();
for (int i = 0; i < bundleCount; i++) {
progressIndicator.setFraction((double) i / bundleCount);
SelectedBundle selectedBundle = myRunConfiguration.getBundlesToDeploy().get(i);
if (selectedBundle.isModule()) {
// use the output jar name if it is a module
String name = selectedBundle.getName();
Module module = moduleManager.findModuleByName(name);
if (module == null) {
throw new CantRunException("Module '" + name + "' no longer exists. Please check your run configuration.");
}
OsmorcFacet facet = OsmorcFacet.getInstance(module);
if (facet == null) {
throw new CantRunException("Module '" + name + "' has no OSGi facet. Please check your run configuration.");
}
selectedBundle.setBundlePath(facet.getConfiguration().getJarFileLocation());
selectedBundles.add(selectedBundle);
// add all the library dependencies of the bundle
List<String> paths = bundleCompiler.bundlifyLibraries(module);
for (String path : paths) {
selectedBundles.add(new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "Dependency", path));
}
} else {
if (selectedBundles.contains(selectedBundle)) {
// if the user selected a dependency as runnable library, we need to replace the dependency with
// the runnable library part
selectedBundles.remove(selectedBundle);
}
selectedBundles.add(selectedBundle);
}
}
// filter out bundles which have the same symbolic name
Map<String, SelectedBundle> filteredBundles = new HashMap<>();
for (SelectedBundle selectedBundle : selectedBundles) {
String path = selectedBundle.getBundlePath();
if (path != null) {
String name = CachingBundleInfoProvider.getBundleSymbolicName(path);
String version = CachingBundleInfoProvider.getBundleVersion(path);
String key = name + version;
if (!filteredBundles.containsKey(key)) {
filteredBundles.put(key, selectedBundle);
}
}
}
List<SelectedBundle> sortedBundles = ContainerUtil.newArrayList(filteredBundles.values());
Collections.sort(sortedBundles, START_LEVEL_COMPARATOR);
result.set(sortedBundles);
} catch (CantRunException e) {
error.set(e);
} catch (OsgiBuildException e) {
LOG.warn(e);
error.set(new CantRunException(e.getMessage()));
} catch (Throwable t) {
LOG.error(t);
error.set(new CantRunException("Internal error: " + t.getMessage()));
} finally {
token.finish();
}
}
});
if (!result.isNull()) {
return result.get();
} else {
throw error.get();
}
}
use of org.osmorc.facet.OsmorcFacet in project intellij-plugins by JetBrains.
the class AdditionalJARContentsWatcherManager method updateWatcherSetup.
public void updateWatcherSetup() {
OsmorcFacet osmorcFacet = OsmorcFacet.getInstance(myModule);
if (osmorcFacet != null) {
List<VirtualFile> newAdditionalJARContents = new ArrayList<>();
OsmorcFacetConfiguration osmorcFacetConfiguration = osmorcFacet.getConfiguration();
List<Pair<String, String>> jarContents = osmorcFacetConfiguration.getAdditionalJARContents();
for (Pair<String, String> jarContent : jarContents) {
VirtualFile file = myFileSystem.findFileByPath(jarContent.getFirst());
if (file != null) {
newAdditionalJARContents.add(file);
}
}
List<LocalFileSystem.WatchRequest> toRemove = new ArrayList<>();
for (Iterator<VirtualFile> jarContentsIterator = myAdditionalBundleJARContents.iterator(); jarContentsIterator.hasNext(); ) {
VirtualFile file = jarContentsIterator.next();
if (!newAdditionalJARContents.contains(file)) {
jarContentsIterator.remove();
for (Iterator<LocalFileSystem.WatchRequest> watchIterator = myWatchRequests.iterator(); watchIterator.hasNext(); ) {
LocalFileSystem.WatchRequest watchRequest = watchIterator.next();
if (Comparing.strEqual(file.getPath(), watchRequest.getRootPath())) {
toRemove.add(watchRequest);
watchIterator.remove();
}
}
}
}
List<String> toAdd = new ArrayList<>();
for (VirtualFile newAdditionalJARContent : newAdditionalJARContents) {
if (!myAdditionalBundleJARContents.contains(newAdditionalJARContent)) {
toAdd.add(newAdditionalJARContent.getPath());
myAdditionalBundleJARContents.add(newAdditionalJARContent);
}
}
Set<LocalFileSystem.WatchRequest> requests = myFileSystem.replaceWatchedRoots(toRemove, toAdd, null);
myWatchRequests.addAll(requests);
} else {
cleanup();
}
}
use of org.osmorc.facet.OsmorcFacet in project intellij-plugins by JetBrains.
the class PackageAccessibilityInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (!(file instanceof PsiClassOwner) || !checkTests && ProjectRootsUtil.isInTestSource(file)) {
return null;
}
final OsmorcFacet facet = OsmorcFacet.getInstance(file);
if (facet == null) {
return null;
}
final List<ProblemDescriptor> problems = ContainerUtil.newSmartList();
DependenciesBuilder.analyzeFileDependencies(file, new DependenciesBuilder.DependencyProcessor() {
@Override
public void process(PsiElement place, PsiElement dependency) {
if (dependency instanceof PsiClass) {
Problem problem = checkAccessibility((PsiClass) dependency, facet);
if (problem != null) {
problems.add(manager.createProblemDescriptor(place, problem.message, isOnTheFly, problem.fixes, problem.type));
}
}
}
}, DependencyVisitorFactory.VisitorOptions.SKIP_IMPORTS);
return problems.isEmpty() ? null : problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of org.osmorc.facet.OsmorcFacet in project intellij-plugins by JetBrains.
the class ViewGeneratedManifestGroup method getChildren.
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
if (e != null) {
Project project = e.getProject();
if (project != null) {
List<AnAction> actions = null;
for (Module module : ModuleManager.getInstance(project).getModules()) {
OsmorcFacet facet = OsmorcFacet.getInstance(module);
if (facet != null) {
String jarFilePath = facet.getConfiguration().getJarFileLocation();
if (!jarFilePath.isEmpty()) {
String title = "[" + module.getName() + "] " + PathUtil.getFileName(jarFilePath);
ViewManifestAction action = new ViewManifestAction(title, jarFilePath);
if (actions == null)
actions = ContainerUtil.newSmartList();
actions.add(action);
}
}
}
if (actions != null) {
return actions.toArray(new AnAction[actions.size()]);
}
}
}
return AnAction.EMPTY_ARRAY;
}
Aggregations