Java Code Examples for org.apache.maven.model.Dependency#setOptional()

The following examples show how to use org.apache.maven.model.Dependency#setOptional() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultPomDependenciesConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Dependency createMavenDependency(ModuleDependency dependency, String name, String type, String scope, String classifier,
        Set<Configuration> configurations) {
    Dependency mavenDependency =  new Dependency();
    mavenDependency.setGroupId(dependency.getGroup());
    if (dependency instanceof ProjectDependency) {
        mavenDependency.setArtifactId(determineProjectDependencyArtifactId((ProjectDependency) dependency));
    } else {
        mavenDependency.setArtifactId(name);
    }
    mavenDependency.setVersion(dependency.getVersion());
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setOptional(false);
    mavenDependency.setClassifier(classifier);
    mavenDependency.setExclusions(getExclusions(dependency, configurations));
    return mavenDependency;
}
 
Example 2
Source File: DefaultPomDependenciesConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Dependency createMavenDependency(ModuleDependency dependency, String name, String type, String scope, String classifier,
        Set<Configuration> configurations) {
    Dependency mavenDependency =  new Dependency();
    mavenDependency.setGroupId(dependency.getGroup());
    if (dependency instanceof ProjectDependency) {
        mavenDependency.setArtifactId(determineProjectDependencyArtifactId((ProjectDependency) dependency));
    } else {
        mavenDependency.setArtifactId(name);
    }
    mavenDependency.setVersion(dependency.getVersion());
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setOptional(false);
    mavenDependency.setClassifier(classifier);
    mavenDependency.setExclusions(getExclusions(dependency, configurations));
    return mavenDependency;
}
 
Example 3
Source File: DefaultPomDependenciesConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Dependency createMavenDependency(ModuleDependency dependency, String name, String type, String scope, String classifier,
        Set<Configuration> configurations) {
    Dependency mavenDependency =  new Dependency();
    mavenDependency.setGroupId(dependency.getGroup());
    if (dependency instanceof ProjectDependency) {
        mavenDependency.setArtifactId(determineProjectDependencyArtifactId((ProjectDependency) dependency));
    } else {
        mavenDependency.setArtifactId(name);
    }
    mavenDependency.setVersion(dependency.getVersion());
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setOptional(false);
    mavenDependency.setClassifier(classifier);
    mavenDependency.setExclusions(getExclusions(dependency, configurations));
    return mavenDependency;
}
 
Example 4
Source File: DefaultPomDependenciesConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Dependency createMavenDependency(ModuleDependency dependency, String name, String type, String scope, String classifier,
        Set<Configuration> configurations) {
    Dependency mavenDependency =  new Dependency();
    mavenDependency.setGroupId(dependency.getGroup());
    if (dependency instanceof ProjectDependency) {
        mavenDependency.setArtifactId(determineProjectDependencyArtifactId((ProjectDependency) dependency));
    } else {
        mavenDependency.setArtifactId(name);
    }
    mavenDependency.setVersion(dependency.getVersion());
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setOptional(false);
    mavenDependency.setClassifier(classifier);
    mavenDependency.setExclusions(getExclusions(dependency, configurations));
    return mavenDependency;
}
 
Example 5
Source File: ExternalBomResolver.java    From sundrio with Apache License 2.0 6 votes vote down vote up
private Dependency toMavenDependency(org.eclipse.aether.graph.Dependency from) {
    org.eclipse.aether.artifact.Artifact fromArt = from.getArtifact();

    Dependency dependency = new Dependency();
    dependency.setGroupId(fromArt.getGroupId());
    dependency.setArtifactId(fromArt.getArtifactId());
    dependency.setVersion(fromArt.getVersion());
    dependency.setType(fromArt.getExtension());
    dependency.setScope(Artifact.SCOPE_COMPILE.equals(from.getScope()) ? null : from.getScope());
    dependency.setClassifier(fromArt.getClassifier());
    dependency.setOptional(dependency.isOptional());

    if (from.getExclusions() != null && from.getExclusions().size() > 0) {
        List<Exclusion> exclusions = new LinkedList<Exclusion>();
        for (org.eclipse.aether.graph.Exclusion fromEx : from.getExclusions()) {
            Exclusion ex = new Exclusion();
            ex.setGroupId(fromEx.getGroupId());
            ex.setArtifactId(fromEx.getArtifactId());
            exclusions.add(ex);
        }
        dependency.setExclusions(exclusions);
    }

    return dependency;
}
 
Example 6
Source File: PomChangeDependency.java    From butterfly with MIT License 5 votes vote down vote up
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    TOExecutionResult result;

    Dependency dependency = getDependency(model, groupId, artifactId);
    if (dependency != null) {
        model.removeDependency(dependency);

        if (removeVersion) dependency.setVersion(null); else if (version != null) dependency.setVersion(version);
        if (removeScope) dependency.setScope(null); else if (scope != null) dependency.setScope(scope);
        if (removeType) dependency.setType(null); else if (type != null) dependency.setType(type);
        if (removeOptional) dependency.setOptional(null); else if (optional != null) dependency.setOptional(optional);

        model.addDependency(dependency);

        String details = String.format("Dependency %s:%s has been changed in %s", groupId, artifactId, getRelativePath());
        result = TOExecutionResult.success(this, details);
    } else {
        String message = String.format("Dependency %s:%s is not present in %s", groupId, artifactId, getRelativePath());

        switch (ifNotPresent) {
            case Warn:
                result = TOExecutionResult.warning(this, new TransformationOperationException(message));
                break;
            case NoOp:
                result = TOExecutionResult.noOp(this, message);
                break;
            case Fail:
                // Fail is the default
            default:
                result = TOExecutionResult.error(this, new TransformationOperationException(message));
                break;
        }
    }

    return result;
}
 
Example 7
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 5 votes vote down vote up
private static Dependency toDependency(Artifact artifact) {
    Dependency dependency = new Dependency();
    dependency.setGroupId(artifact.getGroupId());
    dependency.setArtifactId(artifact.getArtifactId());
    dependency.setVersion(artifact.getVersion());
    dependency.setType(artifact.getType());
    dependency.setScope(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) ? null : artifact.getScope());
    dependency.setClassifier(artifact.getClassifier());
    dependency.setOptional(artifact.isOptional());
    return dependency;
}
 
Example 8
Source File: MavenHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Convert an artifact to a dependency.
 *
 * @param artifact the artifact to convert.
 * @return the result of the conversion.
 */
@SuppressWarnings("static-method")
public Dependency toDependency(Artifact artifact) {
	final Dependency result = new Dependency();
	result.setArtifactId(artifact.getArtifactId());
	result.setClassifier(artifact.getClassifier());
	result.setGroupId(artifact.getGroupId());
	result.setOptional(artifact.isOptional());
	result.setScope(artifact.getScope());
	result.setType(artifact.getType());
	result.setVersion(artifact.getVersion());
	return result;
}
 
Example 9
Source File: Mojo.java    From capsule-maven-plugin with MIT License 5 votes vote down vote up
private Dependency toDependency(final Artifact artifact) {
	if (artifact == null) return null;
	final Dependency dependency = new Dependency();
	dependency.setGroupId(artifact.getGroupId());
	dependency.setArtifactId(artifact.getArtifactId());
	dependency.setVersion(artifact.getVersion());
	dependency.setScope(artifact.getScope());
	dependency.setClassifier(artifact.getClassifier());
	dependency.setOptional(artifact.isOptional());
	if (dependency.getScope() == null || dependency.getScope().isEmpty()) dependency.setScope("compile");
	return dependency;
}