org.jboss.forge.addon.dependencies.Dependency Java Examples

The following examples show how to use org.jboss.forge.addon.dependencies.Dependency. 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: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static Properties loadComponentProperties(Dependency dependency) {
    Properties answer = new Properties();

    try {
        // is it a JAR file
        File file = dependency.getArtifact().getUnderlyingResourceObject();
        if (file != null && file.getName().toLowerCase().endsWith(".jar")) {
            URL url = new URL("file:" + file.getAbsolutePath());
            URLClassLoader child = new URLClassLoader(new URL[]{url});

            InputStream is = child.getResourceAsStream("META-INF/services/org/apache/camel/component.properties");
            if (is != null) {
                answer.load(is);
            }
        }
    } catch (Throwable e) {
        // ignore
    }

    return answer;
}
 
Example #2
Source File: CamelCommandsHelper.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static Result ensureCamelArtifactIdAdded(Project project, CamelComponentDetails details, DependencyInstaller dependencyInstaller) {
    String groupId = details.getGroupId();
    String artifactId = details.getArtifactId();
    Dependency core = CamelProjectHelper.findCamelCoreDependency(project);
    if (core == null) {
        return Results.fail("The project does not include camel-core");
    }

    // we want to use same version as camel-core if its a camel component
    // otherwise use the version from the dto
    String version;
    if ("org.apache.camel".equals(groupId)) {
        version = core.getCoordinate().getVersion();
    } else {
        version = details.getVersion();
    }
    DependencyBuilder component = DependencyBuilder.create().setGroupId(groupId)
            .setArtifactId(artifactId).setVersion(version);

    // install the component
    dependencyInstaller.install(project, component);
    return null;
}
 
Example #3
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static String extractComponentJavaType(Dependency dependency, String scheme) {
    try {
        // is it a JAR file
        File file = dependency.getArtifact().getUnderlyingResourceObject();
        if (file != null && file.getName().toLowerCase().endsWith(".jar")) {
            URL url = new URL("file:" + file.getAbsolutePath());
            URLClassLoader child = new URLClassLoader(new URL[]{url});

            InputStream is = child.getResourceAsStream("META-INF/services/org/apache/camel/component/" + scheme);
            if (is != null) {
                Properties props = new Properties();
                props.load(is);
                return (String) props.get("class");
            }
        }
    } catch (Throwable e) {
        // ignore
    }

    return null;
}
 
Example #4
Source File: CamelLanguagesCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public Set<String> getLanguageNamesFromClasspath() {
    if (core == null) {
        return null;
    }

    Set<String> names = new TreeSet<>();

    // only include existing languages we already have on classpath
    Set<Dependency> artifacts = findCamelArtifacts(project);
    for (Dependency dep : artifacts) {
        Set<String> languages = languagesFromArtifact(camelCatalog, dep.getCoordinate().getArtifactId());
        names.addAll(languages);
    }

    return names;
}
 
Example #5
Source File: CamelLanguagesCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public Iterable<LanguageDto> getValueChoices() {
    if (core == null) {
        return null;
    }

    List<String> names = camelCatalog.findLanguageNames();

    // filter out existing languages we already have
    Set<Dependency> artifacts = findCamelArtifacts(project);
    for (Dependency dep : artifacts) {
        Set<String> languages = languagesFromArtifact(camelCatalog, dep.getCoordinate().getArtifactId());
        names.removeAll(languages);
    }

    List<LanguageDto> answer = new ArrayList<>();
    for (String name : names) {
        LanguageDto dto = createLanguageDto(camelCatalog, name);
        answer.add(dto);
    }

    return answer;
}
 
Example #6
Source File: CamelComponentsCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public Iterable<String> getValueNames(String label) {
    // need to find camel-core so we known the camel version
    Dependency core = CamelProjectHelper.findCamelCoreDependency(project);
    if (core == null) {
        return null;
    }

    List<String> names = getComponentNames();

    if (label != null && !"<all>".equals(label)) {
        names = filterByLabel(names, label);
    }

    if (consumerOnly) {
        names = filterByConsumerOnly(names);
    }
    if (producerOnly) {
        names = filterByProducerOnly(names);
    }
    if (mustHaveOptions) {
        names = filterByMustHaveOptions(names);
    }

    return names;
}
 
Example #7
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static boolean isCamelComponentArtifact(Dependency dependency) {
    try {
        // is it a JAR file
        File file = dependency.getArtifact().getUnderlyingResourceObject();
        if (file != null && file.getName().toLowerCase().endsWith(".jar")) {
            URL url = new URL("file:" + file.getAbsolutePath());
            URLClassLoader child = new URLClassLoader(new URL[]{url});

            // custom component
            InputStream is = child.getResourceAsStream("META-INF/services/org/apache/camel/component.properties");
            if (is != null) {
                IOHelpers.close(is);
                return true;
            }
        }
    } catch (Throwable e) {
        // ignore
    }

    return false;
}
 
Example #8
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static boolean hasDependency(Project project, String groupId, String artifactId, String version) {
    List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies();
    for (Dependency d : dependencies) {
        boolean match = d.getCoordinate().getGroupId().equals(groupId);
        if (match && artifactId != null) {
            match = d.getCoordinate().getArtifactId().equals(artifactId);
        }
        if (match && version != null) {
            match = d.getCoordinate().getVersion().equals(version);
        }
        if (match) {
            return match;
        }
    }
    return false;
}
 
Example #9
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static boolean hasManagedDependency(Project project, String groupId, String artifactId, String version) {
    List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getManagedDependencies();
    for (Dependency d : dependencies) {
        boolean match = d.getCoordinate().getGroupId().equals(groupId);
        if (match && artifactId != null) {
            match = d.getCoordinate().getArtifactId().equals(artifactId);
        }
        if (match && version != null) {
            match = d.getCoordinate().getVersion().equals(version);
        }
        if (match) {
            return match;
        }
    }
    return false;
}
 
Example #10
Source File: CamelDataFormatsCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public Iterable<DataFormatDto> getValueChoices() {
    if (core == null) {
        return null;
    }

    List<String> names = camelCatalog.findDataFormatNames();

    // filter out existing dataformats we already have
    Set<Dependency> artifacts = findCamelArtifacts(project);
    for (Dependency dep : artifacts) {
        Set<String> languages = dataFormatsFromArtifact(camelCatalog, dep.getCoordinate().getArtifactId());
        names.removeAll(languages);
    }

    List<DataFormatDto> answer = new ArrayList<>();
    for (String name : names) {
        DataFormatDto dto = createDataFormatDto(camelCatalog, name);
        answer.add(dto);
    }

    return answer;
}
 
Example #11
Source File: FunktionArchetypeSelectionWizardStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    UIContext uiContext = context.getUIContext();
    Project project = (Project) uiContext.getAttributeMap().get(Project.class);
    Archetype chosenArchetype = archetype.getValue();
    String coordinate = chosenArchetype.getGroupId() + ":" + chosenArchetype.getArtifactId() + ":"
            + chosenArchetype.getVersion();
    DependencyQueryBuilder depQuery = DependencyQueryBuilder.create(coordinate);
    String repository = chosenArchetype.getRepository();
    if (!Strings.isNullOrEmpty(repository)) {
        if (repository.endsWith(".xml")) {
            int lastRepositoryPath = repository.lastIndexOf('/');
            if (lastRepositoryPath > -1)
                repository = repository.substring(0, lastRepositoryPath);
        }
        if (!repository.isEmpty()) {
            depQuery.setRepositories(new DependencyRepository("archetype", repository));
        }
    }
    Dependency resolvedArtifact = dependencyResolver.resolveArtifact(depQuery);
    FileResource<?> artifact = resolvedArtifact.getArtifact();
    MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
    File fileRoot = project.getRoot().reify(DirectoryResource.class).getUnderlyingResourceObject();
    ArchetypeHelper archetypeHelper = new ArchetypeHelper(artifact.getResourceInputStream(), fileRoot,
            metadataFacet.getProjectGroupName(), metadataFacet.getProjectName(), metadataFacet.getProjectVersion());
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    archetypeHelper.setPackageName(facet.getBasePackage());
    archetypeHelper.execute();
    return Results.success();
}
 
Example #12
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected Set<String> discoverCustomCamelComponentsOnClasspathAndAddToCatalog(CamelCatalog camelCatalog, Project project) {
    Set<String> answer = new LinkedHashSet<>();

    // find the dependency again because forge don't associate artifact on the returned dependency when installed
    MavenDependencyFacet facet = project.getFacet(MavenDependencyFacet.class);
    List<Dependency> list = facet.getEffectiveDependencies();

    for (Dependency dep : list) {
        Properties properties = loadComponentProperties(dep);
        if (properties != null) {
            String components = (String) properties.get("components");
            if (components != null) {
                String[] part = components.split("\\s");
                for (String scheme : part) {
                    if (!camelCatalog.findComponentNames().contains(scheme)) {
                        // find the class name
                        String javaType = extractComponentJavaType(dep, scheme);
                        if (javaType != null) {
                            String json = loadComponentJSonSchema(dep, scheme);
                            if (json != null) {
                                camelCatalog.addComponent(scheme, javaType, json);
                                answer.add(scheme);
                            }
                        }
                    }
                }
            }
        }
    }

    return answer;
}
 
Example #13
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static String loadComponentJSonSchema(Dependency dependency, String scheme) {
    String answer = null;

    String path = null;
    String javaType = extractComponentJavaType(dependency, scheme);
    if (javaType != null) {
        int pos = javaType.lastIndexOf(".");
        path = javaType.substring(0, pos);
        path = path.replace('.', '/');
        path = path + "/" + scheme + ".json";
    }

    if (path != null) {
        try {
            // is it a JAR file
            File file = dependency.getArtifact().getUnderlyingResourceObject();
            if (file != null && file.getName().toLowerCase().endsWith(".jar")) {
                URL url = new URL("file:" + file.getAbsolutePath());
                URLClassLoader child = new URLClassLoader(new URL[]{url});

                InputStream is = child.getResourceAsStream(path);
                if (is != null) {
                    answer = loadText(is);
                }
            }
        } catch (Throwable e) {
            // ignore
        }
    }

    return answer;
}
 
Example #14
Source File: CamelComponentsCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public Iterable<ComponentDto> getValueChoices(String label) {
    // need to find camel-core so we known the camel version
    Dependency core = CamelProjectHelper.findCamelCoreDependency(project);
    if (core == null) {
        return null;
    }

    List<String> names = getComponentNames();

    if (label != null && !"<all>".equals(label)) {
        names = filterByLabel(names, label);
    }

    if (consumerOnly) {
        names = filterByConsumerOnly(names);
    }
    if (producerOnly) {
        names = filterByProducerOnly(names);
    }
    if (mustHaveOptions) {
        names = filterByMustHaveOptions(names);
    }

    List<ComponentDto> answer = new ArrayList<>();
    for (String filter : names) {
        ComponentDto dto = createComponentDto(camelCatalog, filter);
        answer.add(dto);
    }
    return answer;
}
 
Example #15
Source File: CamelGetOverviewCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    Project project = getSelectedProject(context);

    // does the project already have camel?
    Dependency core = findCamelCoreDependency(project);
    if (core == null) {
        return Results.fail("The project does not include camel-core");
    }

    ProjectDto camelProject = new ProjectDto();

    ResourcesFacet resourcesFacet = project.getFacet(ResourcesFacet.class);
    WebResourcesFacet webResourcesFacet = null;
    if (project.hasFacet(WebResourcesFacet.class)) {
        webResourcesFacet = project.getFacet(WebResourcesFacet.class);
    }

    // use value choices instead of completer as that works better in web console
    XmlEndpointsCompleter xmlEndpointCompleter = new XmlEndpointsCompleter(resourcesFacet, webResourcesFacet, null);
    JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);

    // use value choices instead of completer as that works better in web console
    RouteBuilderEndpointsCompleter javaEndpointsCompleter = new RouteBuilderEndpointsCompleter(javaSourceFacet, null);

    camelProject.addEndpoints(javaEndpointsCompleter.getEndpoints());
    camelProject.addEndpoints(xmlEndpointCompleter.getEndpoints());

    CamelCurrentComponentsFinder componentsFinder = new CamelCurrentComponentsFinder(getCamelCatalog(), project);
    List<ComponentDto> currentComponents = componentsFinder.findCurrentComponents();
    camelProject.setComponents(currentComponents);

    String result = formatResult(camelProject);
    return Results.success(result);
}
 
Example #16
Source File: ThorntailFacet.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void installFractions(Iterable<FractionDescriptor> selectedFractions)
{
   DependencyFacet facet = getFaceted().getFacet(DependencyFacet.class);
   addSwarmBOM();
   for (FractionDescriptor descriptor : selectedFractions)
   {
      Dependency dependency = DependencyBuilder.create()
               .setGroupId(descriptor.getGroupId())
               .setArtifactId(descriptor.getArtifactId());
      if (!facet.hasEffectiveDependency(dependency))
      {
         facet.addDirectDependency(dependency);
      }
   }
}
 
Example #17
Source File: ThorntailFacet.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
public List<FractionDescriptor> getFractions()
{
   MavenFacet maven = getFaceted().getFacet(MavenFacet.class);
   Model pom = maven.getModel();
   List<org.apache.maven.model.Dependency> dependencies = pom.getDependencies();
   return FractionList.get().getFractionDescriptors()
            .stream()
            .filter(d -> !d.isInternal() && !alreadyInstalled(d.getArtifactId(), dependencies))
            .sorted(comparing(FractionDescriptor::getArtifactId))
            .collect(toList());
}
 
Example #18
Source File: ThorntailFacet.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
public List<FractionDescriptor> getInstalledFractions()
{
   MavenFacet maven = getFaceted().getFacet(MavenFacet.class);
   Model pom = maven.getModel();
   List<org.apache.maven.model.Dependency> dependencies = pom.getDependencies();
   return FractionList.get().getFractionDescriptors()
            .stream()
            .filter(d -> alreadyInstalled(d.getArtifactId(), dependencies))
            .collect(toList());
}
 
Example #19
Source File: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public void extractArtifact(Coordinate artifactCoords, File targetDir) throws IOException, DependencyException
{
    final DependencyQueryBuilder query = DependencyQueryBuilder.create(artifactCoords);
    Dependency dependency = depsResolver.resolveArtifact(query);
    FileResource<?> artifact = dependency.getArtifact();
    ZipUtil.unzipToFolder(new File(artifact.getFullyQualifiedName()), targetDir);
}
 
Example #20
Source File: FabricArchetypeCatalogFactory.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public ArchetypeCatalog getArchetypeCatalog() {
    if (cachedArchetypes == null) {
        String version = VersionHelper.fabric8ArchetypesVersion();

        Coordinate coordinate = CoordinateBuilder.create()
                .setGroupId("io.fabric8.archetypes")
                .setArtifactId("archetypes-catalog")
                .setVersion(version)
                .setPackaging("jar");

        // load the archetype-catalog.xml from inside the JAR
        Dependency dependency = resolver.get().resolveArtifact(DependencyQueryBuilder.create(coordinate));
        if (dependency != null) {
            try {
                String name = dependency.getArtifact().getFullyQualifiedName();
                URL url = new URL("file", null, name);
                URLClassLoader loader = new URLClassLoader(new URL[]{url});
                InputStream is = loader.getResourceAsStream("archetype-catalog.xml");
                if (is != null) {
                    cachedArchetypes = new ArchetypeCatalogXpp3Reader().read(is);
                }
            } catch (Exception e) {
                LOG.log(Level.WARNING, "Error while retrieving archetypes due " + e.getMessage(), e);
            }
        }
    }
    return cachedArchetypes;
}
 
Example #21
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the list has the given dependency
 */
public static boolean hasDependency(List<org.apache.maven.model.Dependency> dependencies, String groupId, String artifactId) {
    if (dependencies != null) {
        for (org.apache.maven.model.Dependency dependency : dependencies) {
            if (Objects.equal(groupId, dependency.getGroupId()) && Objects.equal(artifactId, dependency.getArtifactId())) {
                return true;
            }
        }
    }
    return false;
}
 
Example #22
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the pom has the given dependency
 */
public static boolean hasDependency(Model pom, String groupId, String artifactId) {
    if (pom != null) {
        List<org.apache.maven.model.Dependency> dependencies = pom.getDependencies();
        return hasDependency(dependencies, groupId, artifactId);
    }
    return false;
}
 
Example #23
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the dependency was added or false if its already there
 */
public static boolean ensureMavenDependencyAdded(Project project, DependencyInstaller dependencyInstaller, String groupId, String artifactId, String scope) {
    List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies();
    for (Dependency d : dependencies) {
        if (groupId.equals(d.getCoordinate().getGroupId()) && artifactId.equals(d.getCoordinate().getArtifactId())) {
            getLOG().debug("Project already includes:  " + groupId + ":" + artifactId + " for version: " + d.getCoordinate().getVersion());
            return false;
        }
    }

    DependencyBuilder component = DependencyBuilder.create().
            setGroupId(groupId).
            setArtifactId(artifactId);

    if (scope != null) {
        component.setScopeType(scope);
    }

    String version = MavenHelpers.getVersion(groupId, artifactId);
    if (Strings.isNotBlank(version)) {
        component = component.setVersion(version);
        getLOG().debug("Adding pom.xml dependency:  " + groupId + ":" + artifactId + " version: " + version + " scope: " + scope);
    } else {
        getLOG().debug("No version could be found for:  " + groupId + ":" + artifactId);
    }
    dependencyInstaller.install(project, component);
    return true;
}
 
Example #24
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Set<Dependency> findCustomCamelArtifacts(Project project) {
    Set<Dependency> answer = new LinkedHashSet<Dependency>();

    List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies();
    for (Dependency d : dependencies) {
        if (isCamelComponentArtifact(d)) {
            answer.add(d);
        }
    }
    return answer;
}
 
Example #25
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Set<Dependency> findCamelArtifacts(Project project) {
    Set<Dependency> answer = new LinkedHashSet<Dependency>();

    List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies();
    for (Dependency d : dependencies) {
        if ("org.apache.camel".equals(d.getCoordinate().getGroupId())) {
            answer.add(d);
        }
    }
    return answer;
}
 
Example #26
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Dependency findCamelArtifactDependency(Project project, String artifactId) {
    List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies();
    for (Dependency d : dependencies) {
        if ("org.apache.camel".equals(d.getCoordinate().getGroupId()) && artifactId.equals(d.getCoordinate().getArtifactId())) {
            return d;
        }
    }
    return null;
}
 
Example #27
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public static Dependency findCamelBlueprintDependency(Project project) {
    return findCamelArtifactDependency(project, "camel-blueprint");
}
 
Example #28
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public static Dependency findCamelCoreDependency(Project project) {
    return findCamelArtifactDependency(project, "camel-core");
}
 
Example #29
Source File: ThorntailFacet.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
private boolean alreadyInstalled(String artifactId, List<org.apache.maven.model.Dependency> dependencies)
{
   return dependencies.stream().anyMatch((dep) -> dep.getArtifactId().equals(artifactId));
}
 
Example #30
Source File: CamelProjectHelper.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public static Dependency findCamelSpringDependency(Project project) {
    return findCamelArtifactDependency(project, "camel-spring");
}