Search in sources :

Example 1 with MavenProjectProblem

use of org.eclipse.che.maven.data.MavenProjectProblem in project che by eclipse.

the class MavenServerService method reconcilePom.

@GET
@Path("pom/reconcile")
@ApiOperation(value = "Reconcile pom.xml file")
@ApiResponses({ @ApiResponse(code = 200, message = "OK") })
@Produces("application/json")
public List<Problem> reconcilePom(@ApiParam(value = "The paths to pom.xml file which need to be reconciled") @QueryParam("pompath") String pomPath) {
    VirtualFileEntry entry = null;
    List<Problem> result = new ArrayList<>();
    try {
        entry = cheProjectManager.getProjectsRoot().getChild(pomPath);
        if (entry == null) {
            return result;
        }
        Model.readFrom(entry.getVirtualFile());
        org.eclipse.che.api.vfs.Path path = entry.getPath();
        String pomContent = entry.getVirtualFile().getContentAsString();
        MavenProject mavenProject = mavenProjectManager.findMavenProject(ResourcesPlugin.getWorkspace().getRoot().getProject(path.getParent().toString()));
        if (mavenProject == null) {
            return result;
        }
        List<MavenProjectProblem> problems = mavenProject.getProblems();
        int start = pomContent.indexOf("<project ") + 1;
        int end = start + "<project ".length();
        List<Problem> problemList = problems.stream().map(mavenProjectProblem -> DtoFactory.newDto(Problem.class).withError(true).withSourceStart(start).withSourceEnd(end).withMessage(mavenProjectProblem.getDescription())).collect(Collectors.toList());
        result.addAll(problemList);
    } catch (ServerException | ForbiddenException | IOException e) {
        LOG.error(e.getMessage(), e);
    } catch (XMLTreeException exception) {
        Throwable cause = exception.getCause();
        if (cause != null && cause instanceof SAXParseException) {
            result.add(createProblem(entry, (SAXParseException) cause));
        }
    }
    return result;
}
Also used : MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) Inject(com.google.inject.Inject) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) Document(org.eclipse.jface.text.Document) MavenProgressNotifier(org.eclipse.che.plugin.maven.server.core.MavenProgressNotifier) QueryParam(javax.ws.rs.QueryParam) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Model(org.eclipse.che.ide.maven.tools.Model) BadLocationException(org.eclipse.jface.text.BadLocationException) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TEXT_XML(javax.ws.rs.core.MediaType.TEXT_XML) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Response(javax.ws.rs.core.Response) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ProjectManager(org.eclipse.che.api.project.server.ProjectManager) Collections(java.util.Collections) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ArrayList(java.util.ArrayList) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) IOException(java.io.IOException) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) SAXParseException(org.xml.sax.SAXParseException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with MavenProjectProblem

use of org.eclipse.che.maven.data.MavenProjectProblem in project che by eclipse.

the class MavenModelReader method doRead.

private ModelReadingResult doRead(File pom) {
    List<MavenProjectProblem> problems = new ArrayList<>();
    Set<String> enabledProfiles = new HashSet<>();
    MavenModel result = new MavenModel();
    fillModelByDefaults(result);
    Model model = null;
    try {
        model = Model.readFrom(pom);
    } catch (IOException e) {
        problems.add(MavenProjectProblem.newProblem(pom.getPath(), e.getMessage(), MavenProblemType.SYNTAX));
    }
    if (model == null) {
        return new ModelReadingResult(result, problems, enabledProfiles);
    }
    final MavenKey parentKey;
    if (model.getParent() == null) {
        parentKey = result.getParent().getMavenKey();
    } else {
        Parent modelParent = model.getParent();
        parentKey = new MavenKey(modelParent.getGroupId(), modelParent.getArtifactId(), modelParent.getVersion());
        MavenParent parent = new MavenParent(parentKey, modelParent.getRelativePath());
        result.setParent(parent);
    }
    final MavenKey mavenKey = new MavenKey(getNotNull(model.getGroupId(), parentKey.getGroupId()), model.getArtifactId(), getNotNull(model.getVersion(), parentKey.getVersion()));
    result.setMavenKey(mavenKey);
    if (model.getPackaging() != null) {
        result.setPackaging(model.getPackaging());
    }
    result.setName(model.getName());
    final List<String> modules = model.getModules();
    if (modules != null) {
        result.setModules(new ArrayList<>(model.getModules()));
    }
    Map<String, String> properties = model.getProperties();
    Properties prop = new Properties();
    if (properties != null) {
        prop.putAll(properties);
    }
    result.setProperties(prop);
    final Build build = model.getBuild();
    if (build != null) {
        final String sourceDirectory = build.getSourceDirectory();
        if (sourceDirectory != null) {
            result.getBuild().setSources(singletonList(sourceDirectory));
        }
        final String testSourceDirectory = build.getTestSourceDirectory();
        if (testSourceDirectory != null) {
            result.getBuild().setTestSources(singletonList(testSourceDirectory));
        }
        result.getBuild().setResources(convertResources(build.getResources()));
    }
    //TODO add profiles
    return new ModelReadingResult(result, problems, enabledProfiles);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenParent(org.eclipse.che.maven.data.MavenParent) Parent(org.eclipse.che.ide.maven.tools.Parent) ArrayList(java.util.ArrayList) MavenParent(org.eclipse.che.maven.data.MavenParent) IOException(java.io.IOException) Properties(java.util.Properties) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenBuild(org.eclipse.che.maven.data.MavenBuild) Build(org.eclipse.che.ide.maven.tools.Build) Model(org.eclipse.che.ide.maven.tools.Model) MavenModel(org.eclipse.che.maven.data.MavenModel) HashSet(java.util.HashSet)

Example 3 with MavenProjectProblem

use of org.eclipse.che.maven.data.MavenProjectProblem in project che by eclipse.

the class MavenProject method generateProblems.

private List<MavenProjectProblem> generateProblems() {
    List<MavenProjectProblem> result = new ArrayList<>();
    result.addAll(info.problems);
    result.addAll(info.modulesNameToPath.entrySet().stream().filter(entry -> !project.getFolder(entry.getKey()).exists()).map(entry -> new MavenProjectProblem(getPomPath(), "Can't find module: " + entry.getKey(), MavenProblemType.DEPENDENCY)).collect(Collectors.toList()));
    result.addAll(getDependencies().stream().filter(artifact -> !artifact.isResolved()).map(artifact -> new MavenProjectProblem(getPomPath(), "Can't find dependency: " + artifact.getDisplayString(), MavenProblemType.DEPENDENCY)).collect(Collectors.toList()));
    //TODO add unresolved plugins and extensions
    return result;
}
Also used : MavenServerManager(org.eclipse.che.plugin.maven.server.MavenServerManager) MavenPlugin(org.eclipse.che.maven.data.MavenPlugin) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenConstants(org.eclipse.che.maven.data.MavenConstants) HashMap(java.util.HashMap) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IPath(org.eclipse.core.runtime.IPath) MavenResource(org.eclipse.che.maven.data.MavenResource) Map(java.util.Map) IFile(org.eclipse.core.resources.IFile) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) Properties(java.util.Properties) Collection(java.util.Collection) Set(java.util.Set) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) Collectors(java.util.stream.Collectors) PathUtil(org.eclipse.che.commons.lang.PathUtil) File(java.io.File) Objects(java.util.Objects) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Path(org.eclipse.core.runtime.Path) Element(org.jdom.Element) MavenProblemType(org.eclipse.che.maven.data.MavenProblemType) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) ArrayList(java.util.ArrayList)

Example 4 with MavenProjectProblem

use of org.eclipse.che.maven.data.MavenProjectProblem in project che by eclipse.

the class MavenServerImpl method createResult.

private MavenServerResult createResult(File pom, MavenResult mavenResult) throws RemoteException {
    List<MavenProjectProblem> problems = new ArrayList<>();
    Set<MavenKey> unresolvedArtifacts = new HashSet<>();
    validate(pom, mavenResult.getExceptions(), problems);
    MavenProject project = mavenResult.getMavenProject();
    if (project == null) {
        return new MavenServerResult(null, problems, unresolvedArtifacts);
    }
    MavenModel model = null;
    try {
        DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult();
        org.eclipse.aether.graph.DependencyNode dependencyNode = null;
        if (resolutionResult != null) {
            dependencyNode = resolutionResult.getDependencyGraph();
        }
        List<org.eclipse.aether.graph.DependencyNode> dependencyNodes = null;
        if (dependencyNode != null) {
            dependencyNodes = dependencyNode.getChildren();
        }
        model = MavenModelUtil.convertProjectToModel(project, dependencyNodes, new File(localRepo.getBasedir()));
    } catch (Exception e) {
        validate(project.getFile(), Collections.singletonList(e), problems);
    }
    List<String> activeProfiles = getActiveProfiles(project);
    MavenProjectInfo projectInfo = new MavenProjectInfo(model, null, activeProfiles);
    return new MavenServerResult(projectInfo, problems, unresolvedArtifacts);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) ArrayList(java.util.ArrayList) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenProject(org.apache.maven.project.MavenProject) MavenModel(org.eclipse.che.maven.data.MavenModel) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ArrayList (java.util.ArrayList)4 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)4 HashSet (java.util.HashSet)3 MavenKey (org.eclipse.che.maven.data.MavenKey)3 MavenModel (org.eclipse.che.maven.data.MavenModel)3 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 Properties (java.util.Properties)2 Collectors (java.util.stream.Collectors)2 Model (org.eclipse.che.ide.maven.tools.Model)2 MavenServerWrapper (org.eclipse.che.plugin.maven.server.MavenServerWrapper)2 Inject (com.google.inject.Inject)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RemoteException (java.rmi.RemoteException)1 Collection (java.util.Collection)1