Search in sources :

Example 1 with PomMigrationEditor

use of org.kie.workbench.common.project.migration.cli.maven.PomMigrationEditor in project kie-wb-common by kiegroup.

the class PomMigrationTool method processWorkspaceProject.

private void processWorkspaceProject(WorkspaceProject workspaceProject, String jsonPath, MigrationServicesCDIWrapper cdiWrapper) {
    if (systemMigrationWasExecuted(cdiWrapper)) {
        PomMigrationEditor editor = new PomMigrationEditor();
        final int[] counter = { 0 };
        Files.walkFileTree(Paths.convert(workspaceProject.getRootPath()), new SimpleFileVisitor<org.uberfire.java.nio.file.Path>() {

            @Override
            public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException {
                org.uberfire.backend.vfs.Path visitedVFSPath = Paths.convert(visitedPath);
                String fileName = visitedVFSPath.getFileName();
                File file = visitedPath.toFile();
                if (file.isFile() && fileName.equals(POM_DOT_XML)) {
                    try {
                        Model model;
                        if (jsonPath.isEmpty()) {
                            model = editor.updatePom(visitedPath, cdiWrapper);
                        } else {
                            model = editor.updatePom(visitedPath, jsonPath, cdiWrapper);
                        }
                        if (!model.getBuild().getPlugins().isEmpty()) {
                            counter[0]++;
                        }
                    } catch (Exception e) {
                        system.err().println("Error reading from filename [" + fileName + "] (error below).");
                        e.printStackTrace(system.err());
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });
        system.out().println("Migrated " + counter[0] + " POMs for project: " + workspaceProject.getName());
    }
}
Also used : PomMigrationEditor(org.kie.workbench.common.project.migration.cli.maven.PomMigrationEditor) FileVisitResult(org.uberfire.java.nio.file.FileVisitResult) IOException(org.uberfire.java.nio.IOException) IOException(org.uberfire.java.nio.IOException) Model(org.apache.maven.model.Model) File(java.io.File) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes)

Aggregations

File (java.io.File)1 Model (org.apache.maven.model.Model)1 PomMigrationEditor (org.kie.workbench.common.project.migration.cli.maven.PomMigrationEditor)1 IOException (org.uberfire.java.nio.IOException)1 FileVisitResult (org.uberfire.java.nio.file.FileVisitResult)1 BasicFileAttributes (org.uberfire.java.nio.file.attribute.BasicFileAttributes)1