use of com.cedricziel.idea.typo3.domain.TYPO3ExtensionDefinition in project idea-php-typo3-plugin by cedricziel.
the class ExtensionDefinitionFactory method fromComposerManifest.
/**
* Reads a composer manifest and compiles it into a {@link TYPO3ExtensionDefinition}, if possible.
*
* @param composerManifest The manifest virtual file system entry to parse
* @return The derived extension definition.
* @throws IOException thrown if reading the manifest fails.
*/
private static TYPO3ExtensionDefinition fromComposerManifest(VirtualFile composerManifest) throws IOException {
TYPO3ExtensionDefinition extensionDefinition = new TYPO3ExtensionDefinition();
extensionDefinition.setRootDirectory(composerManifest.getParent());
JsonElement jsonElement = ComposerConfigUtils.parseJson(composerManifest);
if (jsonElement.isJsonObject()) {
JsonObject jsonObject = jsonElement.getAsJsonObject();
String packageName = "";
String composerPackageType = "";
String extensionKey = "";
JsonElement nameElement = jsonObject.get("name");
if (nameElement == null) {
return null;
}
packageName = nameElement.getAsString();
JsonElement typeElement = jsonObject.get("type");
if (typeElement.isJsonPrimitive()) {
composerPackageType = typeElement.getAsString();
if (!isValidPackageType(composerPackageType)) {
return null;
}
}
extensionDefinition.setPackageName(packageName);
/*
Here we either extract the extension key from the composer manifest or
guess the extension key from the package name.
*/
if (jsonObject.has("extra") && !extractExtensionKeyFromComposerExtras(jsonObject.getAsJsonObject()).isEmpty()) {
extensionKey = extractExtensionKeyFromComposerExtras(jsonObject.getAsJsonObject());
} else {
extensionKey = extensionKeyFromPackageName(packageName);
if (composerPackageType.equals(COMPOSER_TYPE_CMS_FRAMEWORK)) {
if ("cms_".equals(extensionKey.substring(0, 4))) {
extensionKey = extensionKey.substring(4);
}
}
}
extensionDefinition.setExtensionKey(extensionKey);
}
return extensionDefinition;
}
use of com.cedricziel.idea.typo3.domain.TYPO3ExtensionDefinition in project idea-php-typo3-plugin by cedricziel.
the class ExtensionDefinitionFactory method fromDirectory.
public static TYPO3ExtensionDefinition fromDirectory(VirtualDirectoryImpl virtualDirectory) {
TYPO3ExtensionDefinition extensionDefinition = null;
// try finding composer manifest
VirtualFileSystemEntry composerManifest = virtualDirectory.findChild("composer.json");
if (composerManifest != null) {
try {
extensionDefinition = fromComposerManifest(composerManifest);
} catch (IOException e) {
e.printStackTrace();
}
}
return extensionDefinition != null ? extensionDefinition : null;
}
use of com.cedricziel.idea.typo3.domain.TYPO3ExtensionDefinition in project idea-php-typo3-plugin by cedricziel.
the class TYPO3ExtensionUtil method findContainingExtension.
/**
* Traverses the given directories and returns the first valid
* extension definition that's applicable.
*
* @param directories List of directories to analyze
*/
public static TYPO3ExtensionDefinition findContainingExtension(PsiDirectory[] directories) {
for (PsiDirectory directory : directories) {
VirtualDirectoryImpl virtualFile = (VirtualDirectoryImpl) directory.getVirtualFile();
while (!isExtensionRootDirectory(virtualFile)) {
if (virtualFile.getParent() == null) {
return null;
}
virtualFile = virtualFile.getParent();
}
TYPO3ExtensionDefinition extensionDefinition = ExtensionDefinitionFactory.fromDirectory(virtualFile);
if (extensionDefinition != null) {
return extensionDefinition;
}
}
return null;
}
use of com.cedricziel.idea.typo3.domain.TYPO3ExtensionDefinition in project idea-php-typo3-plugin by cedricziel.
the class GenerateFscElementAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
Project project = anActionEvent.getProject();
if (project == null) {
return;
}
ToolWindow toolWindow = anActionEvent.getData(PlatformDataKeys.TOOL_WINDOW);
if (toolWindow == null) {
return;
}
PsiDirectory[] psiDirectories = ActionUtil.findDirectoryFromActionEvent(anActionEvent);
if (psiDirectories.length == 0) {
return;
}
TYPO3ExtensionDefinition extensionDefinition = TYPO3ExtensionUtil.findContainingExtension(psiDirectories);
if (extensionDefinition == null) {
Messages.showErrorDialog("Could not extract extension from working directory. Does your extension contain a composer manifest?", "Error While Trying to Find Extension");
return;
}
GenerateFscElementForm.create(toolWindow.getComponent(), project, extensionDefinition);
}
Aggregations