Example usage for org.springframework.ide.eclipse.boot.core SpringBootStarter getDependency

List of usage examples for org.springframework.ide.eclipse.boot.core SpringBootStarter getDependency

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.core SpringBootStarter getDependency.

Prototype

public IMavenCoordinates getDependency() 

Source Link

Usage

From source file:org.springframework.ide.eclipse.boot.core.internal.MavenSpringBootProject.java

@Override
public void setStarters(Collection<SpringBootStarter> _starters) throws CoreException {
    try {/*w w  w  . j a  va 2s .  c o  m*/
        final Set<MavenId> starters = new HashSet<>();
        for (SpringBootStarter s : _starters) {
            starters.add(s.getMavenId());
        }

        IFile file = getPomFile();
        performOnDOMDocument(new OperationTuple(file, new Operation() {
            public void process(Document pom) {
                Element depsEl = getChild(pom.getDocumentElement(), DEPENDENCIES);
                List<Element> children = findChilds(depsEl, DEPENDENCY);
                for (Element c : children) {
                    //We only care about 'starter' dependencies. Leave everything else alone.
                    // Also... don't touch nodes that are already there, unless they are to
                    // be removed. This way we don't mess up versions, comments or other stuff
                    // that a user may have inserted via manual edits.
                    String aid = getTextValue(findChild(c, ARTIFACT_ID));
                    String gid = getTextValue(findChild(c, GROUP_ID));
                    if (aid != null && gid != null) { //ignore invalid entries that don't have gid or aid
                        if (isKnownStarter(new MavenId(gid, aid))) {
                            MavenId id = new MavenId(gid, aid);
                            boolean keep = starters.remove(id);
                            if (!keep) {
                                depsEl.removeChild(c);
                            }
                        }
                    }
                }

                //if 'starters' is not empty at this point, it contains remaining ids we have not seen
                // in the pom, so we need to add them.
                for (MavenId mid : starters) {
                    SpringBootStarter starter = getStarter(mid);
                    createDependency(depsEl, starter.getDependency(), starter.getScope());
                    createBomIfNeeded(pom, starter.getBom());
                    createRepoIfNeeded(pom, starter.getRepo());
                }
            }

        }));
    } catch (Throwable e) {
        throw ExceptionUtil.coreException(e);
    }
}

From source file:org.springframework.ide.eclipse.boot.ui.EnableDisableBootDevtools.java

@Override
public void run(IAction action) {
    try {/*from  w  w w .ja  va 2s . c o  m*/
        SpringBootStarter devtools = getAvaibleDevtools(bootProject);
        if (hasDevTools(bootProject)) {
            bootProject.removeMavenDependency(devtools.getMavenId());
        } else {
            if (devtools != null) {
                bootProject.addMavenDependency(devtools.getDependency(), /*preferManaged*/true);
            } else {
                MessageDialog.openError(activePart.getSite().getShell(),
                        "Boot Devtools Dependency could not be added", explainFailure());
            }
        }
    } catch (Exception e) {
        BootActivator.log(e);
        MessageDialog.openError(activePart.getSite().getShell(), "Unexpected failure",
                "The action to add/remove devtools unexpectedly failed with an error:\n"
                        + ExceptionUtil.getMessage(e) + "\n"
                        + "The error log may contain further information.");
    }
}