-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
475 additions
and
9 deletions.
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
1 change: 1 addition & 0 deletions
1
bundles/com.e1c.v8codestyle.autosort/.settings/org.eclipse.core.resources.prefs
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/com/e1c/v8codestyle/internal/autosort/cli/messages_ru.properties=UTF-8 | ||
encoding//src/com/e1c/v8codestyle/internal/autosort/messages_ru.properties=UTF-8 | ||
encoding/<project>=UTF-8 | ||
encoding/plugin_ru.properties=UTF-8 |
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
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
41 changes: 41 additions & 0 deletions
41
.../com.e1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/cli/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,41 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2023, 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.v8codestyle.internal.autosort.cli; | ||
|
||
import org.eclipse.osgi.util.NLS; | ||
|
||
/** | ||
* @author Dmitriy Marmyshev | ||
* | ||
*/ | ||
final class Messages | ||
extends NLS | ||
{ | ||
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$ | ||
public static String SortCommand_Description; | ||
public static String SortCommand_Project__0__did_not_import_into_workspace; | ||
public static String SortCommand_Project__0__not_found_in_workspace; | ||
public static String SortCommand_Project_names_Description; | ||
public static String SortCommand_Project_paths_Description; | ||
public static String SortCommand_Sort_project__0__finished; | ||
public static String SortCommand_Sort_projects__0; | ||
static | ||
{ | ||
// initialize resource bundle | ||
NLS.initializeMessages(BUNDLE_NAME, Messages.class); | ||
} | ||
|
||
private Messages() | ||
{ | ||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
...m.e1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/cli/SortCommand.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,176 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2023, 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.v8codestyle.internal.autosort.cli; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.core.runtime.Status; | ||
|
||
import com._1c.g5.v8.dt.core.operations.ProjectPipelineJob; | ||
import com._1c.g5.v8.dt.core.platform.IDtProject; | ||
import com.e1c.g5.v8.dt.cli.api.Argument; | ||
import com.e1c.g5.v8.dt.cli.api.CliCommand; | ||
import com.e1c.g5.v8.dt.cli.api.components.BaseCliCommand; | ||
import com.e1c.v8codestyle.autosort.AutoSortPreferences; | ||
import com.e1c.v8codestyle.autosort.ISortService; | ||
import com.e1c.v8codestyle.internal.autosort.AutoSortPlugin; | ||
import com.google.inject.Inject; | ||
|
||
/** | ||
* The CLI command allows to import and to sort project in workspace or to sort existing project in workspace. | ||
* When it runs on each project it turns on default sort settings if not set up. | ||
* | ||
* @author Dmitriy Marmyshev | ||
*/ | ||
public class SortCommand | ||
extends BaseCliCommand | ||
{ | ||
|
||
private final ISortService sortService; | ||
|
||
@Inject | ||
public SortCommand(ISortService sortService) | ||
{ | ||
this.sortService = sortService; | ||
} | ||
|
||
/** | ||
* Import projects into workspace and sort projects. | ||
* | ||
* @param projectPaths the project paths where to find all projects recursively | ||
* @return the status of command | ||
*/ | ||
@CliCommand(command = "sort-project", value = "SortCommand_Description") | ||
public IStatus importAndSortProjects(@Argument(value = "--projects", elementType = Path.class, | ||
descriptor = "SortCommand_Project_paths_Description") Path[] projectPaths) | ||
{ | ||
if (projectPaths == null || projectPaths.length == 0) | ||
{ | ||
return Status.OK_STATUS; | ||
} | ||
|
||
Path[] paths = new Path[projectPaths.length]; | ||
for (int i = 0; i < projectPaths.length; i++) | ||
{ | ||
Path path = projectPaths[i]; | ||
paths[i] = path.toAbsolutePath(); | ||
} | ||
|
||
Collection<File> projectFilePaths = findProjectsRecursively(paths); | ||
|
||
List<IDtProject> projects = new ArrayList<>(); | ||
for (File prjectFile : projectFilePaths) | ||
{ | ||
IDtProject dtProject = startDtProject(prjectFile.getParentFile().toPath()); | ||
if (dtProject != null && dtProject.getWorkspaceProject() != null) | ||
{ | ||
projects.add(dtProject); | ||
} | ||
else | ||
{ | ||
logError( | ||
MessageFormat.format(Messages.SortCommand_Project__0__did_not_import_into_workspace, prjectFile)); | ||
} | ||
} | ||
if (projects.isEmpty()) | ||
{ | ||
// here we tried to import any project but not found - so command should be unsuccessful | ||
return Status.CANCEL_STATUS; | ||
} | ||
|
||
sortProjects(projects); | ||
|
||
return Status.OK_STATUS; | ||
} | ||
|
||
/** | ||
* Sort projects that are existing in workspace. | ||
* | ||
* @param projectNames the project names | ||
* @return the status of command | ||
*/ | ||
@CliCommand(command = "sort-project", value = "SortCommand_Description") | ||
public IStatus sortExistingProjects(@Argument(value = "--project-names", elementType = IProject.class, | ||
descriptor = "SortCommand_Project_names_Description") IProject[] projectNames) | ||
{ | ||
if (projectNames == null || projectNames.length == 0) | ||
{ | ||
return Status.OK_STATUS; | ||
} | ||
List<IDtProject> projects = new ArrayList<>(); | ||
|
||
for (int i = 0; i < projectNames.length; i++) | ||
{ | ||
IProject project = projectNames[i]; | ||
if (!project.isAccessible()) | ||
{ | ||
String error = | ||
MessageFormat.format(Messages.SortCommand_Project__0__not_found_in_workspace, project.getName()); | ||
logError(error); | ||
return AutoSortPlugin.createErrorStatus(error, null); | ||
} | ||
waitUntilStarted(project, DT_PROJECT_STARTUP_DURATION); | ||
IDtProject dtProject = getContext().getDtProjectManager().getDtProject(project); | ||
if (dtProject != null && dtProject.getWorkspaceProject() != null) | ||
{ | ||
projects.add(dtProject); | ||
} | ||
else | ||
{ | ||
logError( | ||
MessageFormat.format(Messages.SortCommand_Project__0__not_found_in_workspace, project.getName())); | ||
} | ||
} | ||
|
||
sortProjects(projects); | ||
|
||
return Status.OK_STATUS; | ||
} | ||
|
||
private void sortProjects(List<IDtProject> projects) | ||
{ | ||
String info = MessageFormat.format(Messages.SortCommand_Sort_projects__0, | ||
projects.stream().map(IDtProject::getName).collect(Collectors.joining(", "))); //$NON-NLS-1$ | ||
getContext().getLogger().info(info); | ||
|
||
for (IDtProject project : projects) | ||
{ | ||
if (!AutoSortPreferences.isAutoSortEnabled(project.getWorkspaceProject())) | ||
{ | ||
AutoSortPreferences.setupProjectDefault(project.getWorkspaceProject()); | ||
} | ||
exclusiveOperation("Sort-MD-objects", project, ProjectPipelineJob.AFTER_BUILD_DD, () -> { //$NON-NLS-1$ | ||
sortService.sortAllMetadata(project, new NullProgressMonitor()); | ||
return null; | ||
}); | ||
|
||
info = MessageFormat.format(Messages.SortCommand_Sort_project__0__finished, project.getName()); | ||
getContext().getLogger().info(info); | ||
} | ||
|
||
for (IDtProject project : projects) | ||
{ | ||
// wait here to build project after sorting, to avoid dropping/stopping project while saving | ||
exclusiveOperation("After-Sort-MD-objects", project, ProjectPipelineJob.AFTER_BUILD_DD, () -> null); //$NON-NLS-1$ | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/cli/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,27 @@ | ||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/) | ||
############################################################################### | ||
# Copyright (C) 2021, 2023, 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 | ||
############################################################################### | ||
|
||
SortCommand_Description = Sort 1C:Enterprise projects with current auto-sort settings. If auto-sorting is not enabled yet, then default sort settings will enable for the project. | ||
|
||
SortCommand_Project__0__did_not_import_into_workspace = Project "{0}" was not imported into workspace | ||
|
||
SortCommand_Project__0__not_found_in_workspace = Project "{0}" was not found in workspace | ||
|
||
SortCommand_Project_names_Description = List of project names, imported into workspace earlier, which will be sorted | ||
|
||
SortCommand_Project_paths_Description = List of project paths, which will be imported into workspace and will be sorted | ||
|
||
SortCommand_Sort_project__0__finished = Sort project "{0}" is finished. | ||
|
||
SortCommand_Sort_projects__0 = Sort projects: {0} |
28 changes: 28 additions & 0 deletions
28
...v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/cli/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,28 @@ | ||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/) | ||
############################################################################### | ||
# Copyright (C) 2021, 2023, 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 | ||
############################################################################### | ||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/) | ||
|
||
SortCommand_Description = Сортирует проекты 1С:Предприятия с текущиими настройками авто-сортировки. Если авто-сортировка еще не была включена, тогда для проекта включатся настройки сортировки по умолчанию. | ||
|
||
SortCommand_Project__0__did_not_import_into_workspace = Проект "{0}" не был импортирован в рабочее пространство | ||
|
||
SortCommand_Project__0__not_found_in_workspace = Проект "{0}" не найден в рабочем пространстве | ||
|
||
SortCommand_Project_names_Description = Список имен проектов, ранее импортированных в рабочее пространство, которые будут отсортированы | ||
|
||
SortCommand_Project_paths_Description = Список путей к проектам, которые будут импортированы в рабочее пространство и отсортированы | ||
|
||
SortCommand_Sort_project__0__finished = Сортировка проекта "{0}" завершена. | ||
|
||
SortCommand_Sort_projects__0 = Сортировать проекты: {0} |
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
Oops, something went wrong.