Search in sources :

Example 1 with Dependency

use of org.eclipse.jkube.kit.common.Dependency in project jkube by eclipse.

the class SpringBootUtilTest method testGetSpringBootDevToolsVersion.

@Test
public void testGetSpringBootDevToolsVersion(@Mocked JavaProject maven_project) {
    // Given
    Dependency p = Dependency.builder().groupId("org.springframework.boot").version("1.6.3").build();
    new Expectations() {

        {
            maven_project.getDependencies();
            result = Collections.singletonList(p);
        }
    };
    // when
    Optional<String> result = SpringBootUtil.getSpringBootDevToolsVersion(maven_project);
    // Then
    assertTrue(result.isPresent());
    assertEquals("1.6.3", result.get());
}
Also used : Expectations(mockit.Expectations) Dependency(org.eclipse.jkube.kit.common.Dependency) Test(org.junit.Test)

Example 2 with Dependency

use of org.eclipse.jkube.kit.common.Dependency in project jkube by eclipse.

the class SpringBootUtilTest method testGetSpringBootVersion.

@Test
public void testGetSpringBootVersion(@Mocked JavaProject maven_project) {
    // Given
    Dependency p = Dependency.builder().groupId("org.springframework.boot").version("1.6.3").build();
    new Expectations() {

        {
            maven_project.getDependencies();
            result = Collections.singletonList(p);
        }
    };
    // when
    Optional<String> result = SpringBootUtil.getSpringBootVersion(maven_project);
    // Then
    assertTrue(result.isPresent());
    assertEquals("1.6.3", result.get());
}
Also used : Expectations(mockit.Expectations) Dependency(org.eclipse.jkube.kit.common.Dependency) Test(org.junit.Test)

Example 3 with Dependency

use of org.eclipse.jkube.kit.common.Dependency in project jkube by eclipse.

the class DependencyEnricherTest method getDummyArtifacts.

private List<Dependency> getDummyArtifacts() {
    List<Dependency> artifacts = new ArrayList<>();
    File aFile = new File(getClass().getResource(ARTIFACT_FILE_PATH).getFile());
    Dependency artifact = Dependency.builder().groupId("g1").artifactId("a1").version("v1").type("jar").scope("compile").file(aFile).build();
    artifacts.add(artifact);
    return artifacts;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.eclipse.jkube.kit.common.Dependency) File(java.io.File)

Example 4 with Dependency

use of org.eclipse.jkube.kit.common.Dependency in project jkube by eclipse.

the class GradleUtil method extractDependencies.

private static List<Dependency> extractDependencies(Project gradleProject, Function<ResolutionResult, Set<? extends DependencyResult>> resolutionToDependency) {
    return new ArrayList<Configuration>(gradleProject.getConfigurations()).stream().filter(GradleUtil::canBeResolved).flatMap(c -> {
        final Map<ComponentIdentifier, ResolvedArtifactResult> artifacts = artifactMap(c);
        return resolutionToDependency.apply(c.getIncoming().getResolutionResult()).stream().filter(ResolvedDependencyResult.class::isInstance).map(ResolvedDependencyResult.class::cast).map(ResolvedDependencyResult::getSelected).filter(rcr -> Objects.nonNull(rcr.getModuleVersion())).map(rcr -> {
            final ModuleVersionIdentifier mvi = rcr.getModuleVersion();
            final Dependency.DependencyBuilder db = Dependency.builder().groupId(mvi.getGroup()).artifactId(mvi.getName()).version(mvi.getVersion());
            final ResolvedArtifactResult artifact = artifacts.get(rcr.getId());
            if (artifact != null) {
                db.scope(c.getName().toLowerCase(Locale.ROOT).contains("test") ? "test" : "compile");
                db.file(artifact.getFile());
                db.type(artifact.getVariant().getAttributes().getAttribute(Attribute.of("artifactType", String.class)));
            }
            return db.build();
        });
    }).distinct().collect(Collectors.toList());
}
Also used : ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) DependencySet(org.gradle.api.artifacts.DependencySet) Function(java.util.function.Function) FileCollection(org.gradle.api.file.FileCollection) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) Attribute(org.gradle.api.attributes.Attribute) Locale(java.util.Locale) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) UnknownDomainObjectException(org.gradle.api.UnknownDomainObjectException) Path(java.nio.file.Path) JavaProject(org.eclipse.jkube.kit.common.JavaProject) Properties(java.util.Properties) Project(org.gradle.api.Project) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Collection(java.util.Collection) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) Plugin(org.eclipse.jkube.kit.common.Plugin) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) Objects(java.util.Objects) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) List(java.util.List) Stream(java.util.stream.Stream) Dependency(org.eclipse.jkube.kit.common.Dependency) Paths(java.nio.file.Paths) PublishArtifactSet(org.gradle.api.artifacts.PublishArtifactSet) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) Collections(java.util.Collections) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) Dependency(org.eclipse.jkube.kit.common.Dependency) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult)

Example 5 with Dependency

use of org.eclipse.jkube.kit.common.Dependency in project jkube by eclipse.

the class DependencyEnricher method addArtifactsWithYaml.

private void addArtifactsWithYaml(Set<URI> artifactSet, String dependencyYaml) throws URISyntaxException {
    final List<Dependency> artifacts = getContext().getDependencies(isIncludeTransitive());
    for (Dependency artifact : artifacts) {
        if ("compile".equals(artifact.getScope()) && "jar".equals(artifact.getType())) {
            File file = artifact.getFile();
            try {
                URI uri = new URI("jar:" + file.toURI() + "!/" + dependencyYaml);
                artifactSet.add(uri);
            } catch (URISyntaxException e) {
                getLog().debug("Failed to create URL for %s: %s", file, e);
            }
        }
    }
    // lets look on the current plugin classpath too
    if (isIncludePlugin()) {
        Enumeration<URL> resources = null;
        try {
            resources = getClass().getClassLoader().getResources(dependencyYaml);
        } catch (IOException e) {
            getLog().error("Could not find %s on the classpath: %s", dependencyYaml, e);
        }
        if (resources != null) {
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                URI uri = url.toURI();
                artifactSet.add(uri);
            }
        }
    }
}
Also used : Dependency(org.eclipse.jkube.kit.common.Dependency) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File) URI(java.net.URI) URL(java.net.URL)

Aggregations

Dependency (org.eclipse.jkube.kit.common.Dependency)6 File (java.io.File)3 Expectations (mockit.Expectations)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Function (java.util.function.Function)1