diff --git a/osmorc/resources/META-INF/plugin.xml b/osmorc/resources/META-INF/plugin.xml index 336b51258c9..2ca99333ace 100644 --- a/osmorc/resources/META-INF/plugin.xml +++ b/osmorc/resources/META-INF/plugin.xml @@ -66,6 +66,8 @@ + + @@ -112,6 +114,7 @@ + diff --git a/osmorc/src/org/jetbrains/osgi/bnd/BndFileType.java b/osmorc/src/org/jetbrains/osgi/bnd/BndFileType.java index f8f1dc176bf..b5013486436 100644 --- a/osmorc/src/org/jetbrains/osgi/bnd/BndFileType.java +++ b/osmorc/src/org/jetbrains/osgi/bnd/BndFileType.java @@ -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 Tibor Malanik + */ +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; + } + } diff --git a/osmorc/src/org/jetbrains/osgi/bnd/BndLanguage.java b/osmorc/src/org/jetbrains/osgi/bnd/BndLanguage.java new file mode 100644 index 00000000000..d7c7c4ef9e9 --- /dev/null +++ b/osmorc/src/org/jetbrains/osgi/bnd/BndLanguage.java @@ -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 Tibor Malanik + */ +public class BndLanguage extends Language { + public static final BndLanguage INSTANCE = new BndLanguage(); + + public BndLanguage() { + super("bnd"); + } +} diff --git a/osmorc/src/org/osmorc/facet/BndOsmorcFrameworkDetector.java b/osmorc/src/org/osmorc/facet/BndOsmorcFrameworkDetector.java new file mode 100644 index 00000000000..4b66900c872 --- /dev/null +++ b/osmorc/src/org/osmorc/facet/BndOsmorcFrameworkDetector.java @@ -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 Tibor Malanik + */ +public class BndOsmorcFrameworkDetector extends FacetBasedFrameworkDetector { + + 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 getFacetType() { + return OsmorcFacetType.getInstance(); + } + + @Override + protected OsmorcFacetConfiguration createConfiguration(Collection files) { + OsmorcFacetConfiguration osmorcFacetConfiguration = getFacetType().createDefaultConfiguration(); + osmorcFacetConfiguration.setManifestGenerationMode(ManifestGenerationMode.Bnd); + osmorcFacetConfiguration.setBndFileLocation(BND_FILE_NAME); + return osmorcFacetConfiguration; + } + + @NotNull + @Override + public ElementPattern createSuitableFilePattern() { + return FileContentPattern.fileContent().with(new PatternCondition("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; + } + +}