Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33 Валидация модели состава автономной конфигурации и квик-фиксы
- Loading branch information
Showing
72 changed files
with
3,618 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
bundles/com.e1c.dt.check.md/markdown/configuration-standalon-content.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Configuration standalone content is correct. | ||
|
||
Checks configuration standalone content elements are valid. | ||
|
||
## Noncompliant Code Example | ||
|
||
## Compliant Solution | ||
|
||
## See |
9 changes: 9 additions & 0 deletions
9
bundles/com.e1c.dt.check.md/markdown/ru/configuration-standalon-content.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Состав автономной конфигурации является корректным | ||
|
||
Проверяет что текущий режим состав автономной конфигурации содержит валидные элементы. | ||
|
||
## Неправильно | ||
|
||
## Правильно | ||
|
||
## См. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
....check.md/src/com/e1c/dt/check/internal/md/fix/ConfigurationStandalonContentCheckFix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
bundles/com.e1c.dt.check.md/src/com/e1c/dt/check/internal/md/fix/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
{ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
bundles/com.e1c.dt.check.md/src/com/e1c/dt/check/internal/md/fix/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
4 changes: 4 additions & 0 deletions
4
bundles/com.e1c.dt.check.md/src/com/e1c/dt/check/internal/md/fix/messages_ru.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=Удалить неконсистентный элемент из состава автономной конфигурации |
67 changes: 67 additions & 0 deletions
67
bundles/com.e1c.dt.check.md/src/com/e1c/dt/check/md/ConfigurationStandalonContentCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...heck.md.itests/src/com/e1c/dt/check/md/itests/ConfigurationStandalonContentCheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.