Search in sources :

Example 1 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration in project intellij-plugins by JetBrains.

the class OsmorcFacetGeneralEditorTab method apply.

@Override
public void apply() throws ConfigurationException {
    OsmorcFacetConfiguration configuration = (OsmorcFacetConfiguration) myEditorContext.getFacet().getConfiguration();
    configuration.setManifestGenerationMode(myControlledByOsmorcRadioButton.isSelected() ? ManifestGenerationMode.OsmorcControlled : myUseBndFileRadioButton.isSelected() ? ManifestGenerationMode.Bnd : myUseBundlorFileRadioButton.isSelected() ? ManifestGenerationMode.Bundlor : ManifestGenerationMode.Manually);
    configuration.setManifestLocation(FileUtil.toSystemIndependentName(myManifestFileChooser.getText()));
    configuration.setUseProjectDefaultManifestFileLocation(myUseProjectDefaultManifestFileLocation.isSelected());
    configuration.setBndFileLocation(FileUtil.toSystemIndependentName(myBndFile.getText()));
    configuration.setBundlorFileLocation(FileUtil.toSystemIndependentName(myBundlorFile.getText()));
    configuration.setDoNotSynchronizeWithMaven(myDoNotSynchronizeFacetCheckBox.isSelected());
    myModified = false;
}
Also used : OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration)

Example 2 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration in project intellij-plugins by JetBrains.

the class OsmorcFacetImporter method reimportFacet.

@Override
protected void reimportFacet(IdeModifiableModelsProvider modelsProvider, Module module, MavenRootModelAdapter mavenRootModelAdapter, OsmorcFacet osmorcFacet, MavenProjectsTree mavenProjectsTree, MavenProject mavenProject, MavenProjectChanges changes, Map<MavenProject, String> mavenProjectStringMap, List<MavenProjectsProcessorTask> mavenProjectsProcessorPostConfigurationTasks) {
    OsmorcFacetConfiguration conf = osmorcFacet.getConfiguration();
    if (conf.isDoNotSynchronizeWithMaven()) {
        return;
    }
    // first off, we get the defaults
    MavenId id = mavenProject.getMavenId();
    conf.setBundleSymbolicName(id.getGroupId() + "." + id.getArtifactId());
    conf.setBundleVersion(ImporterUtil.cleanupVersion(id.getVersion()));
    MavenPlugin plugin = mavenProject.findPlugin(myPluginGroupID, myPluginArtifactID);
    if (plugin == null) {
        return;
    }
    // Check if there are any overrides set up in the maven plugin settings
    // IDEA-63243
    conf.setBundleSymbolicName(computeSymbolicName(mavenProject));
    // to preserve the order of elements
    Map<String, String> props = ContainerUtil.newLinkedHashMap();
    Map<String, String> modelMap = mavenProject.getModelMap();
    String description = modelMap.get("description");
    if (!StringUtil.isEmptyOrSpaces(description)) {
        props.put(Constants.BUNDLE_DESCRIPTION, description);
    }
    String licenses = modelMap.get("licenses");
    if (!StringUtil.isEmptyOrSpaces(licenses)) {
        props.put("Bundle-License", licenses);
    }
    String vendor = modelMap.get("organization.name");
    if (!StringUtil.isEmpty(vendor)) {
        props.put(Constants.BUNDLE_VENDOR, vendor);
    }
    String docUrl = modelMap.get("organization.url");
    if (!StringUtil.isEmptyOrSpaces(docUrl)) {
        props.put(Constants.BUNDLE_DOCURL, docUrl);
    }
    // load versions if any
    Map<String, String> versions = cleanVersions(plugin);
    // now find any additional properties that might have been set up:
    Element instructionsNode = getConfig(mavenProject, "instructions");
    if (instructionsNode != null) {
        boolean useExistingManifest = false;
        for (Element child : instructionsNode.getChildren()) {
            String name = child.getName();
            String value = child.getTextTrim();
            value = value.replaceAll("\\p{Blank}*[\r\n]\\p{Blank}*", "");
            value = substituteVersions(value, versions);
            if (INCLUDE_MANIFEST.equals(name)) {
                conf.setManifestLocation(value);
                conf.setManifestGenerationMode(ManifestGenerationMode.Manually);
                conf.setUseProjectDefaultManifestFileLocation(false);
                useExistingManifest = true;
            } else if (Constants.BUNDLE_VERSION.equals(name)) {
                conf.setBundleVersion(value);
            } else if (Constants.BUNDLE_ACTIVATOR.equals(name)) {
                conf.setBundleActivator(value);
            } else if (!StringUtil.isEmpty(value) && !Constants.BUNDLE_SYMBOLICNAME.equals(name)) {
                if (StringUtil.startsWithChar(name, '_')) {
                    // sanitize instructions
                    name = "-" + name.substring(1);
                }
                props.put(name, value);
            }
        }
        if (!useExistingManifest) {
            conf.setManifestLocation("");
            conf.setManifestGenerationMode(ManifestGenerationMode.OsmorcControlled);
            conf.setUseProjectDefaultManifestFileLocation(true);
        }
    }
    // check if bundle name exists, if not compute it (IDEA-63244)
    if (!props.containsKey(Constants.BUNDLE_NAME)) {
        props.put(Constants.BUNDLE_NAME, computeBundleName(mavenProject));
    }
    // now post-process the settings, to make Embed-Dependency work
    ImporterUtil.postProcessAdditionalProperties(props, mavenProject, module.getProject());
    // Fix for IDEA-63242 - don't merge it with the existing settings, overwrite them
    conf.importAdditionalProperties(props, true);
    // Fix for IDEA-66235 - inherit jar filename from maven
    String jarFileName = mavenProject.getFinalName() + ".jar";
    // FiX for IDEA-67088, preserve existing output path settings on reimport.
    switch(conf.getOutputPathType()) {
        case OsgiOutputPath:
            conf.setJarFileLocation(jarFileName, OutputPathType.OsgiOutputPath);
            break;
        case SpecificOutputPath:
            String path = new File(conf.getJarFilePath(), jarFileName).getPath();
            conf.setJarFileLocation(path, OutputPathType.SpecificOutputPath);
            break;
        default:
            conf.setJarFileLocation(jarFileName, OutputPathType.CompilerOutputPath);
    }
}
Also used : OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenPlugin(org.jetbrains.idea.maven.model.MavenPlugin) Element(org.jdom.Element) File(java.io.File)

Example 3 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration in project intellij-plugins by JetBrains.

the class UnregisteredActivatorInspection method buildVisitor.

@NotNull
@Override
protected PsiElementVisitor buildVisitor(final OsmorcFacet facet, final ProblemsHolder holder, boolean isOnTheFly) {
    if (!(holder.getFile() instanceof PsiClassOwner))
        return PsiElementVisitor.EMPTY_VISITOR;
    return new JavaElementVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            if (file instanceof PsiClassOwner) {
                for (PsiClass psiClass : ((PsiClassOwner) file).getClasses()) {
                    String className = psiClass.getQualifiedName();
                    if (OsgiPsiUtil.isActivator(psiClass) && className != null) {
                        BundleManifest manifest = BundleManifestCache.getInstance(psiClass.getProject()).getManifest(facet.getModule());
                        if (manifest != null && !className.equals(manifest.getBundleActivator())) {
                            LocalQuickFix[] fixes = LocalQuickFix.EMPTY_ARRAY;
                            OsmorcFacetConfiguration configuration = facet.getConfiguration();
                            if (configuration.isManifestManuallyEdited()) {
                                fixes = new LocalQuickFix[] { new RegisterInManifestQuickfix(className) };
                            } else if (configuration.isOsmorcControlsManifest()) {
                                fixes = new LocalQuickFix[] { new RegisterInConfigurationQuickfix(className, configuration) };
                            }
                            PsiElement identifier = unwrap(psiClass.getNameIdentifier());
                            if (identifier != null) {
                                holder.registerProblem(identifier, OsmorcBundle.message("UnregisteredActivatorInspection.message"), fixes);
                            }
                        }
                    }
                }
            }
        }
    };
}
Also used : OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) BundleManifest(org.jetbrains.osgi.project.BundleManifest) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration 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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration in project intellij-plugins by JetBrains.

the class OsmorcFacetJAREditorTab method reset.

@Override
public void reset() {
    OsmorcFacetConfiguration configuration = (OsmorcFacetConfiguration) myEditorContext.getFacet().getConfiguration();
    OutputPathType outputPathType = configuration.getOutputPathType();
    myPlaceInCompilerOutputPathRadioButton.setSelected(outputPathType == CompilerOutputPath);
    myPlaceInProjectWideRadioButton.setSelected(outputPathType == OsgiOutputPath);
    myPlaceInThisPathRadioButton.setSelected(outputPathType == SpecificOutputPath);
    myJarFileTextField.setText(configuration.getJarFileName());
    if (outputPathType == SpecificOutputPath) {
        myJarOutputPathChooser.setText(configuration.getJarFilePath());
    } else {
        myJarOutputPathChooser.setText("");
    }
    myAdditionalJARContentsTableModel.replaceContent(configuration.getAdditionalJARContents());
    myIgnoreFilePatternTextField.setText(configuration.getIgnoreFilePattern());
    myAlwaysRebuildBundleJARCheckBox.setSelected(configuration.isAlwaysRebuildBundleJAR());
    updateGui();
    myModified = false;
}
Also used : OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OutputPathType(org.jetbrains.osgi.jps.model.OutputPathType)

Aggregations

OsmorcFacetConfiguration (org.osmorc.facet.OsmorcFacetConfiguration)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 OsmorcFacet (org.osmorc.facet.OsmorcFacet)4 PsiFile (com.intellij.psi.PsiFile)3 File (java.io.File)3 Module (com.intellij.openapi.module.Module)2 Nullable (org.jetbrains.annotations.Nullable)2 ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)2 OutputPathType (org.jetbrains.osgi.jps.model.OutputPathType)2 Attrs (aQute.bnd.header.Attrs)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Pair (com.intellij.openapi.util.Pair)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ZipFile (java.util.zip.ZipFile)1 Element (org.jdom.Element)1 NotNull (org.jetbrains.annotations.NotNull)1