Skip to content

Commit

Permalink
33 Валидация модели состава автономной конфигурации и квик-фиксы
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfandw committed Jul 12, 2022
1 parent e908dba commit 6606566
Show file tree
Hide file tree
Showing 72 changed files with 3,618 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@

[TOC text bullet hierarchy]

## 0.4.0

- Проверка модели состава автономной конфигурации
- Квик-фикс для исправления некорректных элементов состава автономной конфигурации

## 0.3.0

- Выпуск бета-версии для 1C:EDT 2022.2
Expand Down
3 changes: 3 additions & 0 deletions bundles/com.e1c.dt.check.md/META-INF/MANIFEST.MF
Expand Up @@ -25,11 +25,14 @@ Import-Package: com._1c.g5.v8.bm.core;version="[7.6.0,8.0.0)",
com._1c.g5.v8.dt.metadata.mdclass.impl;version="[10.7.0,11.0.0)",
com._1c.g5.v8.dt.metadata.mdclass.util;version="[5.12.0,6.0.0)",
com._1c.g5.v8.dt.platform.version;version="[2.12.0,3.0.0)",
com._1c.g5.v8.dt.scc;version="[1.0.0,2.0.0)",
com._1c.g5.v8.dt.scc.model;version="[2.0.0,3.0.0)",
com._1c.g5.wiring;version="[2.2.0,3.0.0)",
com._1c.g5.wiring.binder;version="[1.1.0,2.0.0)",
com.e1c.g5.v8.dt.check;version="[2.0.0,3.0.0)",
com.e1c.g5.v8.dt.check.components;version="[2.0.0,3.0.0)",
com.e1c.g5.v8.dt.check.context;version="[2.0.0,3.0.0)",
com.e1c.g5.v8.dt.check.qfix;version="[1.0.0,2.0.0)",
com.e1c.g5.v8.dt.check.qfix.components;version="[1.0.0,2.0.0)",
com.e1c.g5.v8.dt.check.settings;version="[3.0.0,4.0.0)"
Export-Package: com.e1c.dt.check.md;version="0.3.0"
@@ -0,0 +1,9 @@
# Configuration standalone content is correct.

Checks configuration standalone content elements are valid.

## Noncompliant Code Example

## Compliant Solution

## See
@@ -0,0 +1,9 @@
# Состав автономной конфигурации является корректным

Проверяет что текущий режим состав автономной конфигурации содержит валидные элементы.

## Неправильно

## Правильно

## См.
14 changes: 13 additions & 1 deletion bundles/com.e1c.dt.check.md/plugin.xml
Expand Up @@ -40,6 +40,18 @@
<check
category="com.e1c.dt.check.md"
class="com.e1c.dt.check.internal.md.MdReferenceIntegrity">
</check>
</check>

<check
category="com.e1c.dt.check.md"
class="com.e1c.dt.check.internal.md.ExecutableExtensionFactory:com.e1c.dt.check.md.ConfigurationStandalonContentCheck">
</check>

</extension>

<extension point="com.e1c.g5.v8.dt.check.fixes">
<fix
class="com.e1c.dt.check.internal.md.fix.ConfigurationStandalonContentCheckFix">
</fix>
</extension>
</plugin>
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (C) 2022, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.dt.check.internal.md.fix;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;

import com._1c.g5.v8.dt.scc.model.StandaloneContentMdObjectAware;
import com.e1c.dt.check.internal.md.CorePlugin;
import com.e1c.dt.check.md.ConfigurationStandalonContentCheck;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
import com.e1c.g5.v8.dt.check.qfix.components.BasicModelFixContext;
import com.e1c.g5.v8.dt.check.qfix.components.MultiVariantModelBasicFix;
import com.e1c.g5.v8.dt.check.qfix.components.QuickFix;

/**
* The multi-variant fix for {@link ConfigurationStandalonContentCheck} allows to remove bad content item
* from used, unused and priority items.
*
* @author Andrey Volkov
*/
@QuickFix(checkId = "configuration-standalon-content", supplierId = CorePlugin.PLUGIN_ID)
public class ConfigurationStandalonContentCheckFix
extends MultiVariantModelBasicFix
{

@Override
protected void buildVariants()
{
VariantBuilder builder = VariantBuilder.create(this);
builder
.description(Messages.ConfigurationStandalonContentCheckFix_Remove_bad_content_item_title,
Messages.ConfigurationStandalonContentCheckFix_Remove_bad_content_item_description)
.change(this::removeBadContentItem)
.build();
}

private void removeBadContentItem(EObject object, EStructuralFeature feature, BasicModelFixContext context,
IFixSession session)
{
if (object instanceof StandaloneContentMdObjectAware)
{
removeObject(object);
}
}

private void removeObject(EObject object)
{
EObject parent = object.eContainer();
EStructuralFeature containing = object.eContainmentFeature();
if (containing == null || parent == null)
{
return;
}

if (containing.isMany())
{
List<?> list = (List<?>)parent.eGet(containing);
int index = list.indexOf(object);
if (index > -1)
{
list.remove(index);
}
}
}
}
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (C) 2022, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.dt.check.internal.md.fix;

import org.eclipse.osgi.util.NLS;

/**
* Messages.
*
* @author Andrey Volkov
*/
/* package */ final class Messages
extends NLS
{
private static final String BUNDLE_NAME = "com.e1c.dt.check.internal.md.fix.messages"; //$NON-NLS-1$

public static String ConfigurationStandalonContentCheckFix_Remove_bad_content_item_description;
public static String ConfigurationStandalonContentCheckFix_Remove_bad_content_item_title;

static
{
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages()
{
}
}
@@ -0,0 +1,15 @@
###############################################################################
# Copyright (C) 2022, 1C-Soft LLC and others.
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# 1C-Soft LLC - initial API and implementation
###############################################################################

ConfigurationStandalonContentCheckFix_Remove_bad_content_item_description=Bad content item will be removed from standalon content
ConfigurationStandalonContentCheckFix_Remove_bad_content_item_title=Remove bad item from standalon content
@@ -0,0 +1,4 @@
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)

ConfigurationStandalonContentCheckFix_Remove_bad_content_item_description=Неконсистентный элемент будет удален из состава автономной конфигурации
ConfigurationStandalonContentCheckFix_Remove_bad_content_item_title=Удалить неконсистентный элемент из состава автономной конфигурации
@@ -0,0 +1,67 @@
/**
* Copyright (C) 2022, 1C
*/
package com.e1c.dt.check.md;

import org.eclipse.core.runtime.IProgressMonitor;

import com._1c.g5.v8.dt.platform.version.IRuntimeVersionSupport;
import com._1c.g5.v8.dt.platform.version.Version;
import com._1c.g5.v8.dt.scc.ConfigurationStandaloneContentValidator;
import com._1c.g5.v8.dt.scc.model.StandaloneContent;
import com._1c.g5.v8.dt.scc.model.StandaloneContentPackage;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.g5.v8.dt.check.components.BasicCheck;
import com.e1c.g5.v8.dt.check.components.TopObjectFilterExtension;
import com.e1c.g5.v8.dt.check.settings.IssueType;
import com.google.inject.Inject;

/**
* Configuration standalon content check.
*
* @author Andrey Volkov
*/
public class ConfigurationStandalonContentCheck
extends BasicCheck
{
@Inject
private IRuntimeVersionSupport runtimeVersionSupport;

/**
* Check Id.
*/
public static final String CHECK_ID = "configuration-standalon-content"; //$NON-NLS-1$

@Override
public String getCheckId()
{
return CHECK_ID;
}

@Override
protected void configureCheck(CheckConfigurer builder)
{
builder.title(Messages.ConfigurationStandalonContentCheck_Title)
.description(Messages.ConfigurationStandalonContentCheck_Description)
.extension(new TopObjectFilterExtension())
.issueType(IssueType.CRITICAL_DATA_INTEGRITY)
.topObject(StandaloneContentPackage.Literals.STANDALONE_CONTENT)
.features(StandaloneContentPackage.Literals.STANDALONE_CONTENT__PRIORITY_ITEM,
StandaloneContentPackage.Literals.STANDALONE_CONTENT__UNUSED_ITEM,
StandaloneContentPackage.Literals.STANDALONE_CONTENT__USED_ITEM);
}

@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor progressMonitor)
{
StandaloneContent standaloneContent = (StandaloneContent)object;
Version version = runtimeVersionSupport.getRuntimeVersion(standaloneContent);

ConfigurationStandaloneContentValidator.validate(standaloneContent, version)
.entrySet()
.forEach(
error -> error.getValue()
.forEach(errorMessage -> resultAceptor.addIssue(errorMessage, error.getKey())));
}
}
Expand Up @@ -37,6 +37,9 @@
public static String ConfigurationMobileApplicationUrlsCheck_Description;
public static String ConfigurationMobileApplicationUrlsCheck_Empty_base_url;

public static String ConfigurationStandalonContentCheck_Title;
public static String ConfigurationStandalonContentCheck_Description;

static
{
// initialize resource bundle
Expand Down
Expand Up @@ -10,3 +10,6 @@ ConfigurationUsedMobileApplicationFunctionalitiesCheck_Unsupported_property__0=U
ConfigurationMobileApplicationUrlsCheck_Title=Configuration mobile application URLs check
ConfigurationMobileApplicationUrlsCheck_Description=Configuration mobile application URLs check
ConfigurationMobileApplicationUrlsCheck_Empty_base_url=The base URL in the link is not specified

ConfigurationStandalonContentCheck_Title=Configuration standalon content check
ConfigurationStandalonContentCheck_Description=Configuration standalon content check
Expand Up @@ -10,3 +10,6 @@ ConfigurationUsedMobileApplicationFunctionalitiesCheck_Unsupported_property__0=
ConfigurationMobileApplicationUrlsCheck_Title=Проверка базовых URL конфигурации мобильного приложения
ConfigurationMobileApplicationUrlsCheck_Description=Проверка базовых URL конфигурации мобильного приложения
ConfigurationMobileApplicationUrlsCheck_Empty_base_url=Не указан базовый URL в ссылке

ConfigurationStandalonContentCheck_Title=Проверка состава автономной конфигурации
ConfigurationStandalonContentCheck_Description=Проверка состава автономной конфигурации
@@ -0,0 +1,96 @@
/*******************************************************************************
* Copyright (C) 2022, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.dt.check.md.itests;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.Test;

import com._1c.g5.v8.bm.core.IBmObject;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.core.platform.IV8Project;
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
import com.e1c.dt.check.md.ConfigurationStandalonContentCheck;

/**
* Tests for the {@link ConfigurationStandalonContentCheck}
*
* @author Andrey Volkov
*/
public class ConfigurationStandalonContentCheckTest
extends AbstractMdCheckTest
{
@Test
public void ConfigurationStandalonContentCheckUsed() throws Exception
{
// Start project and wait until all checks are performed
IV8Project v8Project = init("ConfigurationStandalonContentCheckUsed");
IDtProject dtProject = v8Project.getDtProject();

waitForDD(dtProject);

Collection<Object> topObjectIds = checkStandalonContent(dtProject, ConfigurationStandalonContentCheck.CHECK_ID);

// Re-validate same object
revalidate(dtProject, topObjectIds, ConfigurationStandalonContentCheck.CHECK_ID);

checkStandalonContent(dtProject, ConfigurationStandalonContentCheck.CHECK_ID);
}

@Test
public void ConfigurationStandalonContentCheckUnused() throws Exception
{
// Start project and wait until all checks are performed
IV8Project v8Project = init("ConfigurationStandalonContentCheckUnused");
IDtProject dtProject = v8Project.getDtProject();

waitForDD(dtProject);

Collection<Object> topObjectIds = checkStandalonContent(dtProject, ConfigurationStandalonContentCheck.CHECK_ID);

// Re-validate same object
revalidate(dtProject, topObjectIds, ConfigurationStandalonContentCheck.CHECK_ID);

checkStandalonContent(dtProject, ConfigurationStandalonContentCheck.CHECK_ID);
}

@Test
public void ConfigurationStandalonContentCheckPriority() throws Exception
{
// Start project and wait until all checks are performed
IV8Project v8Project = init("ConfigurationStandalonContentCheckPriority");
IDtProject dtProject = v8Project.getDtProject();

waitForDD(dtProject);

Collection<Object> topObjectIds =
checkStandalonContent(dtProject, ConfigurationStandalonContentCheck.CHECK_ID);

// Re-validate same object
revalidate(dtProject, topObjectIds, ConfigurationStandalonContentCheck.CHECK_ID);

checkStandalonContent(dtProject, ConfigurationStandalonContentCheck.CHECK_ID);
}

private Collection<Object> checkStandalonContent(IDtProject dtProject, String checkId)
{
Collection<Object> topObjectIds = new ArrayList<>();
Configuration configuration = (Configuration)getTopObjectByFqn("Configuration", dtProject);
IBmObject bmObject = (IBmObject)configuration.getMobileApplicationContent();
Long bmObjectId = bmObject.bmGetId();
checkMarker(dtProject, checkId, bmObjectId);
topObjectIds.add(bmObjectId);
return topObjectIds;
}
}

0 comments on commit 6606566

Please sign in to comment.