Example usage for org.springframework.ide.eclipse.boot.core IMavenCoordinates getArtifactId

List of usage examples for org.springframework.ide.eclipse.boot.core IMavenCoordinates getArtifactId

Introduction

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

Prototype

String getArtifactId();

Source Link

Usage

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

/**
 * Determine the 'managed' version, if any, associate with a given dependency.
 * @return Version string or null./*from  ww  w. ja  va  2  s  . c  o  m*/
 */
private String getManagedVersion(IMavenCoordinates dep) {
    try {
        MavenProject mp = getMavenProject();
        if (mp != null) {
            DependencyManagement managedDeps = mp.getDependencyManagement();
            if (managedDeps != null) {
                List<Dependency> deps = managedDeps.getDependencies();
                if (deps != null && !deps.isEmpty()) {
                    for (Dependency d : deps) {
                        if ("jar".equals(d.getType())) {
                            if (dep.getArtifactId().equals(d.getArtifactId())
                                    && dep.getGroupId().equals(d.getGroupId())) {
                                return d.getVersion();
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        BootActivator.log(e);
    }
    return null;
}

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

@Override
public void addMavenDependency(final IMavenCoordinates dep, final boolean preferManagedVersion,
        final boolean optional) throws CoreException {
    try {//from w w  w .ja v  a 2 s  .c o m
        IFile file = getPomFile();
        performOnDOMDocument(new OperationTuple(file, new Operation() {
            public void process(Document document) {
                Element depsEl = getChild(document.getDocumentElement(), DEPENDENCIES);
                if (depsEl == null) {
                    //TODO: handle this case
                } else {
                    String version = dep.getVersion();
                    String managedVersion = getManagedVersion(dep);
                    if (managedVersion != null) {
                        //Decide whether we can/should inherit the managed version or override it.
                        if (preferManagedVersion || managedVersion.equals(version)) {
                            version = null;
                        }
                    } else {
                        //No managed version. We have to include a version in xml added to the pom.
                    }
                    Element xmlDep = PomHelper.createDependency(depsEl, dep.getGroupId(), dep.getArtifactId(),
                            version);
                    if (optional) {
                        createElementWithText(xmlDep, OPTIONAL, "true");
                        format(xmlDep);
                    }
                }
            }
        }));
    } catch (Throwable e) {
        throw ExceptionUtil.coreException(e);
    }
}

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

/**
 * creates and adds new dependency to the parent. formats the result.
 *//*from   w w  w  .  jav  a2  s.com*/
private Element createDependency(Element parentList, IMavenCoordinates info, String scope) {
    Element dep = createElement(parentList, DEPENDENCY);
    String groupId = info.getGroupId();
    String artifactId = info.getArtifactId();
    String version = info.getVersion();
    String classifier = info.getClassifier();

    if (groupId != null) {
        createElementWithText(dep, GROUP_ID, groupId);
    }
    createElementWithText(dep, ARTIFACT_ID, artifactId);
    if (version != null) {
        createElementWithText(dep, VERSION, version);
    }
    if (classifier != null) {
        createElementWithText(dep, CLASSIFIER, classifier);
    }
    if (scope != null && !scope.equals("compile")) {
        createElementWithText(dep, SCOPE, scope);
    }
    format(dep);
    return dep;
}

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

private boolean hasDevTools(ISpringBootProject bootProject) {
    try {/*from w  w w.  j  a v  a2s.com*/
        List<IMavenCoordinates> deps = bootProject.getDependencies();
        if (deps != null) {
            for (IMavenCoordinates d : deps) {
                if (SPRING_BOOT_DEVTOOLS_AID.equals(d.getArtifactId())) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        BootActivator.log(e);
    }
    return false;
}