Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect osmorc by bnd.bnd file #695

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions osmorc/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<projectImportProvider implementation="org.jetbrains.osgi.bnd.imp.BndProjectImportProvider"/>
<projectImportProvider implementation="org.jetbrains.osgi.bnd.imp.BndModuleImportProvider"/>

<fileType name="bnd" implementationClass="org.jetbrains.osgi.bnd.BndFileType" fieldName="INSTANCE" extensions="bnd" language="bnd"/>

<applicationService serviceImplementation="org.osmorc.settings.ApplicationSettings"/>
<applicationService serviceImplementation="org.osmorc.frameworkintegration.FrameworkIntegratorRegistry"/>
<applicationService serviceImplementation="org.osmorc.obrimport.ObrProvider"/>
Expand Down Expand Up @@ -112,6 +114,7 @@

<facetType implementation="org.osmorc.facet.OsmorcFacetType"/>
<framework.detector implementation="org.osmorc.facet.OsmorcFrameworkDetector"/>
<framework.detector implementation="org.osmorc.facet.BndOsmorcFrameworkDetector"/>
<frameworkSupport implementation="org.osmorc.facet.OsgiFrameworkSupportProvider"/>
<library.type implementation="org.osmorc.facet.OsgiCoreLibraryType"/>
<library.dependencyScopeSuggester implementation="org.osmorc.facet.OsgiLibraryDependencyScopeSuggester"/>
Expand Down
46 changes: 44 additions & 2 deletions osmorc/src/org/jetbrains/osgi/bnd/BndFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,50 @@
*/
package org.jetbrains.osgi.bnd;

// [r.sh] will be extended later to a full-blown file type
public class BndFileType {
import com.intellij.icons.AllIcons;
import com.intellij.openapi.fileTypes.LanguageFileType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
* File type for bnd (osgi bundle) files.
*
* @author <a href="mailto:tibor@malanik.eu">Tibor Malanik</a>
*/
public class BndFileType extends LanguageFileType {

public static final String BND_EXT = "bnd";
public static final String BND_RUN_EXT = "bndrun";

public static BndFileType INSTANCE = new BndFileType();

private BndFileType() {
super(BndLanguage.INSTANCE);
}

@NotNull
@NonNls
public String getName() {
return "bnd";
}

@NotNull
public String getDescription() {
return "bnd";
}

@NotNull
@NonNls
public String getDefaultExtension() {
return BND_EXT;
}

@Nullable
public Icon getIcon() {
return AllIcons.FileTypes.Config;
}

}
29 changes: 29 additions & 0 deletions osmorc/src/org/jetbrains/osgi/bnd/BndLanguage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.osgi.bnd;

import com.intellij.lang.Language;

/**
* @author <a href="mailto:tibor@malanik.eu">Tibor Malanik</a>
*/
public class BndLanguage extends Language {
public static final BndLanguage INSTANCE = new BndLanguage();

public BndLanguage() {
super("bnd");
}
}
79 changes: 79 additions & 0 deletions osmorc/src/org/osmorc/facet/BndOsmorcFrameworkDetector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.osmorc.facet;

import com.intellij.facet.FacetType;
import com.intellij.framework.detection.FacetBasedFrameworkDetector;
import com.intellij.framework.detection.FileContentPattern;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PatternCondition;
import com.intellij.util.ProcessingContext;
import com.intellij.util.indexing.FileContent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.osgi.bnd.BndFileType;
import org.jetbrains.osgi.jps.model.ManifestGenerationMode;

import java.util.Collection;

/**
* Framework detector for bnd files. File needs to be named bnd.bnd
*
* @author <a href="mailto:tibor@malanik.eu">Tibor Malanik</a>
*/
public class BndOsmorcFrameworkDetector extends FacetBasedFrameworkDetector<OsmorcFacet, OsmorcFacetConfiguration> {

private static final String BND_FILE_NAME = "bnd.bnd";
private final Logger logger = Logger.getInstance("#org.osmorc.facet.BndOsmorcFrameworkDetector");

public BndOsmorcFrameworkDetector() {
super("osmorc");
}

@NotNull
@Override
public FacetType<OsmorcFacet, OsmorcFacetConfiguration> getFacetType() {
return OsmorcFacetType.getInstance();
}

@Override
protected OsmorcFacetConfiguration createConfiguration(Collection<VirtualFile> files) {
OsmorcFacetConfiguration osmorcFacetConfiguration = getFacetType().createDefaultConfiguration();
osmorcFacetConfiguration.setManifestGenerationMode(ManifestGenerationMode.Bnd);
osmorcFacetConfiguration.setBndFileLocation(BND_FILE_NAME);
return osmorcFacetConfiguration;
}

@NotNull
@Override
public ElementPattern<FileContent> createSuitableFilePattern() {
return FileContentPattern.fileContent().with(new PatternCondition<FileContent>("bnd file") {
@Override
public boolean accepts(@NotNull FileContent content, ProcessingContext context) {
return content.getFileName().equals(BND_FILE_NAME);
}
});
}

@NotNull
@Override
public FileType getFileType() {
return BndFileType.INSTANCE;
}

}